我有带有下拉列表、标签和文本框的网络表单。如下所示:
<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
问题出现在这样的场景中:
- SetupVisibility() 在页面加载时隐藏文本框和标签。
- 我更改了 ddlTest 下拉列表中的值。
- SetupVisibility() 想要显示文本框和标签,但随后出现错误:
Microsoft JScript - runtime error: Cannot update control with ID: ctl00_CPH1_lblTest. The control does not exist.
问题出在哪里?