值不能为空。参数名:控制 [英] Value cannot be null. Parameter name: control
问题描述
我曾经有过在UpdatePanel作为整个ListView项的包装。
< ASP:的UpdatePanel ID =UpdatePanel1=服务器>
<&的ContentTemplate GT;
< ASP:ListView控件ID =ListView1的=服务器>
<&LayoutTemplate模板GT;
< ASP:占位符ID =itemPlaceholder=服务器/>
< / LayoutTemplate模板>
<&ItemTemplate中GT;
....
< / ItemTemplate中>
< / ASP:的ListView>
< /&的ContentTemplate GT;
<&触发器GT;< /触发器>
< / ASP:的UpdatePanel>
和注册客户端脚本如下...
私人小组ListView1_ItemCommand(BYVAL发件人为对象,BYVAL E上System.Web.UI.WebControls.ListViewCommandEventArgs)处理ListView1.ItemCommand
如果不ClientScript.IsClientScriptBlockRegistered(ME [的GetType(),OtherScript),然后
ScriptManager.RegisterStartupScript(DirectCast(Page.FindControl(UpdatePanel1)的UpdatePanel)的GetType(字符串),alertScript,更新('hpClips','假','增量'),真)
万一
分完
现在我决定换行只是组更新面板ImageButtons的如下...
< ASP:ListView控件ID =ListView1的=服务器>
<&LayoutTemplate模板GT;
< ASP:占位符ID =itemPlaceholder=服务器/>
< / LayoutTemplate模板>
<&ItemTemplate中GT;
< ASP:的UpdatePanel ID =UpdatePanel1=服务器的UpdateMode =始终RenderMode =块>
<&的ContentTemplate GT;
< ASP:ImageButton的ID =btnAttach=服务器的CommandName ='<%#AddC_&放大器;的eval(QID)及_&放大器;的eval(标签)%GT;/>
< ASP:ImageButton的ID =btnFavorite=服务器的CommandName ='<%#AddF_&放大器;的eval(QID)及_&放大器;的eval(标签)%GT;/>
< /&的ContentTemplate GT;
< / ASP:的UpdatePanel>
< / ItemTemplate中>
< / ASP:的ListView>
和我得到了以下错误
值不能为空。参数名:控制
在执行
ScriptManager.RegisterStartupScript(DirectCast(Page.FindControl(UpdatePanel1)的UpdatePanel)的GetType(字符串),alertScript,更新('hpClips','假','增量'),真)
我觉得这与事实UpdatePanel控件没有被发现的事情。和直接投抛出异常。所以,我怎么能解决呢?
谢谢你在前进。
更新:我想这一个了。 (这一次,我没有得到任何异常,但不执行客户端脚本)
私人小组ListView1_ItemCommand(BYVAL发件人为对象,BYVAL E上System.Web.UI.WebControls.ListViewCommandEventArgs)处理ListView1.ItemCommand
昏暗UpdPanel作为新的UpdatePanel
对于每个最多为的UpdatePanel在e.Item.Controls.OfType(中的UpdatePanel)()
UpdPanel =向上
下一个 如果不ClientScript.IsClientScriptBlockRegistered(ME [的GetType(),OtherScript),然后
ScriptManager.RegisterStartupScript(DirectCast(UpdPanel,UpdatePanel的)的GetType(字符串),alertScript,更新('hpClips','假','增量'),真)
万一
分完
固定!以下是卓有成效的
如果不ClientScript.IsClientScriptBlockRegistered(ME [的GetType(),OtherScript),然后
ScriptManager.RegisterStartupScript(Me.Page,Me.GetType(),Guid.NewGuid.ToString,更新('hpClips','假','增量'),真)
万一
资源,帮助
<一个href=\"http://stackoverflow.com/questions/802506/problem-with-scriptmanager-registerstartupscript-in-webcontrol-nested-in-updatepa\">Problem与ScriptManager.RegisterStartupScript中的WebControl嵌套在UpdatePanel中
添加JavaScript的异步回发期间以编程方式使用的RegisterStartupScript
I used to have the UpdatePanel as a wrapper for the whole Listview item.
<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>
and register the client script as follows...
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
Now i decided to wrap only the group of ImageButtons with update panels as follows...
<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>
and i get the following error
Value cannot be null. Parameter name: control
while executing
ScriptManager.RegisterStartupScript(DirectCast(Page.FindControl("UpdatePanel1"), UpdatePanel), GetType(String), "alertScript", "update('hpClips','false','inc')", True)
I think this has to do with the fact that the updatepanel control was not found. And the Direct cast throws the exception. So how could i fix that? Thank you in advance.
UPDATE: I tried this one too. (This time, i get no exception but the client script is not executed)
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
Fixed! The following does the trick
If Not ClientScript.IsClientScriptBlockRegistered(Me.[GetType](), "OtherScript") Then
ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), Guid.NewGuid.ToString, "update('hpClips','false','inc')", True)
End If
Resources that helped
Problem with ScriptManager.RegisterStartupScript in WebControl nested in UpdatePanel
Add JavaScript programmatically using RegisterStartupScript during an Asynchronous postback
这篇关于值不能为空。参数名:控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!