2011-04-10 45 views
0

我曾經有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控件有關。直接投射拋出異常。那我該如何解決這個問題? 預先感謝您。

更新:我也試過這個。 (這一次,我不例外,但客戶端腳本沒有執行)

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

http://stackoverflow.com/questions/3399441/value-cannot-be-null-parameter-名稱控制 – 2011-04-10 13:54:11

+0

@賈尼原諒我?我不太明白,爲什麼這與我的問題有關 – OrElse 2011-04-10 14:24:42

+0

因此,我的意思是這是一個普遍的錯誤,像'對象引用未設置爲對象的實例',檢查視覺工作室捕捉每個異常看看調用拋出異常的堆棧,查看當地人和汽車,你可以通過這種方式找到解決方案。 – 2011-04-11 05:52:57

回答

相關問題