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