Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 值不能为null。参数名称:控件_Asp.net_Ajax_Listview_Asp.net Ajax_Registerstartupscript - Fatal编程技术网

Asp.net 值不能为null。参数名称:控件

Asp.net 值不能为null。参数名称:控件,asp.net,ajax,listview,asp.net-ajax,registerstartupscript,Asp.net,Ajax,Listview,Asp.net Ajax,Registerstartupscript,我曾经将UpdatePanel作为整个Listview项的包装 <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:ListView ID="ListView1" runat="server"> <LayoutTemplate> <asp:PlaceHolder id=

我曾经将UpdatePanel作为整个Listview项的包装

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:ListView ID="ListView1" runat="server">
            <LayoutTemplate>
                <asp:PlaceHolder id="itemPlaceholder" runat="server" />
            </LayoutTemplate>
            <ItemTemplate> 
                '....
            </ItemTemplate>
        </asp:ListView>
    </ContentTemplate>
 <Triggers></Triggers>
</asp:UpdatePanel>
现在我决定只包装一组带有更新面板的ImageButton,如下所示

 Private Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand
    if Not ClientScript.IsClientScriptBlockRegistered(Me.[GetType](), "OtherScript") Then
       ScriptManager.RegisterStartupScript(DirectCast(Page.FindControl("UpdatePanel1"), UpdatePanel), GetType(String), "alertScript", "update('hpClips','false','inc')", True)
    End If
 End sub
<asp:ListView ID="ListView1" runat="server">
    <LayoutTemplate>
        <asp:PlaceHolder id="itemPlaceholder" runat="server" />
    </LayoutTemplate>
    <ItemTemplate> 
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" RenderMode="Block">
            <ContentTemplate>
                <asp:ImageButton ID="btnAttach" runat="server" CommandName='<%# "AddC_" & Eval("QID") & "_" & Eval("Label") %>'/>
                <asp:ImageButton ID="btnFavorite" runat="server" CommandName='<%# "AddF_" & Eval("QID")  & "_" & Eval("Label") %>'/>
            </ContentTemplate>
        </asp:UpdatePanel>
    </ItemTemplate>
</asp:ListView>
执行时
ScriptManager.RegisterStartupScript(DirectCast(Page.FindControl(“UpdatePanel1”)、UpdatePanel)、GetType(String)、“alertScript”、“update('hpClips'、'false'、'inc')、True)

我认为这与找不到updatepanel控件有关。而直接演员则抛出异常。那我该怎么解决呢? 先谢谢你

更新:我也试过这个。(这一次,我没有得到任何例外,但客户端脚本没有执行)


修正!下面的方法可以实现这一目的

If Not ClientScript.IsClientScriptBlockRegistered(Me.[GetType](), "OtherScript") Then
 ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), Guid.NewGuid.ToString, "update('hpClips','false','inc')", True)
End If
有帮助的资源


@Jani对不起?我不太明白,为什么这与我的问题有关,我的意思是这是一个一般性错误,比如
对象引用未设置为对象的实例
,请检查visual studio以捕获每个异常查看引发异常的调用堆栈,查看局部变量和自动变量,你很有可能通过这种方式找到解决办法。
Private Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand
    Dim UpdPanel As New UpdatePanel
    For Each Up As UpdatePanel In e.Item.Controls.OfType(Of UpdatePanel)()
           UpdPanel = Up             
    Next

    if Not ClientScript.IsClientScriptBlockRegistered(Me.[GetType](), "OtherScript") Then
       ScriptManager.RegisterStartupScript(DirectCast(UpdPanel, UpdatePanel), GetType(String), "alertScript", "update('hpClips','false','inc')", True)
    End If
End sub
If Not ClientScript.IsClientScriptBlockRegistered(Me.[GetType](), "OtherScript") Then
 ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), Guid.NewGuid.ToString, "update('hpClips','false','inc')", True)
End If