繁体   English   中英

值不能为空。 参数名称:control

[英]Value cannot be null. Parameter name: control

我曾经将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>

并注册客户端脚本如下...

 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

现在我决定只使用更新面板包装ImageButtons组,如下所示......

<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>

我得到以下错误

Value cannot be null. Parameter name: control

执行ScriptManager.RegisterStartupScript(DirectCast(Page.FindControl("UpdatePanel1"), UpdatePanel), GetType(String), "alertScript", "update('hpClips','false','inc')", True)

我认为这与未找到updatepanel控件的事实有关。 Direct cast抛出异常。 那怎么能解决这个问题呢? 先感谢您。

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

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

资源有所帮助

嵌套在UpdatePanel中的WebControl中的ScriptManager.RegisterStartupScript问题

在异步回发期间使用RegisterStartupScript以编程方式添加JavaScript

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM