我有带下拉列表,标签和文本框的网络表单。如下所示:
<asp:DropDownList ID="ddlTest" runat="server" AutoPostBack="true">
</asp:DropDownList>
<asp:Label ID="lblTest" runat="server" Text="Some text">
</asp:Label>
<asp:TextBox ID="edtTest" runat="server">
</asp:TextBox>
我想显示/隐藏标签和文本框,具体取决于下拉列表中选择的值。所以我添加了RadAjaxManader:
<rad:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<rad:AjaxSetting AjaxControlID="ddlTest">
<UpdatedControls>
<rad:AjaxUpdatedControl ControlID="lblTest" />
<rad:AjaxUpdatedControl ControlID="edtTest" />
</UpdatedControls>
</rad:AjaxSetting>
</AjaxSettings>
</rad:RadAjaxManager>
和过程“SetupVisibility”从下拉列表中获取值,做了一些诽谤并决定是否显示或隐藏标签和文本框。当我使用这样的程序时:
Protected Sub ddlTest_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTest.SelectedIndexChanged
SetupVisibility()
End Sub
它运行良好,但现在我想在加载页面时调用SetupVisibility:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SetupVisibility()
End Sub
在这种情况下会出现问题:
Microsoft JScript - runtime error: Cannot update control with ID: ctl00_CPH1_lblTest. The control does not exist.
问题出在哪里?答案 0 :(得分:3)
我已经解决了这个问题。我已将文本框和标签包装到div和面板中:
<div id="panelTest_DIV" runat="server">
<asp:Panel ID="panelTest" runat="server">
<asp:Label ID="lblTest" runat="server" Text="Some text..."></asp:Label><br />
<asp:TextBox ID="edtTest" runat="server"></asp:TextBox>
</asp:Panel>
</div>
和AjaxManager:
<rad:AjaxSetting AjaxControlID="ddlTest">
<UpdatedControls>
<rad:AjaxUpdatedControl ControlID="panelTest_DIV" />
</UpdatedControls>
</rad:AjaxSetting>
在SetupVisibility()
内我设置了panelTest.Visibility
。它解决了这个问题。
答案 1 :(得分:0)
页面初始化时会触发Page_Init。在此活动期间,没有保证已创建控件..
尝试将代码放在Page_Load中,因为当时保证已创建控件。