我对 FindControl 功能有疑问。问题如下:
aspx:
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<table class="inputTable">
<tr><td>
<asp:CheckBox ID="Extern" AutoPostBack="True" OnCheckedChanged="OnCheckedChangedMethod" runat="server" />
</td><td>Externes Unternehmen</td></tr>
<tr>
<td>
<asp:TextBox ID="Firmierung" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Firmierung" Display="Dynamic"
ErrorMessage="RequiredFieldValidator"
Text="Bitte geben Sie die Firmierung ein."></asp:RequiredFieldValidator>
</td>
</tr>
</table>
aspx.cs:
protected void OnCheckedChangedMethod(object sender, EventArgs e)
{
if (Extern.Checked)
{
Control ctr = FindControl("RequiredFieldValidator1");
if (ctr != null)
{
ctr.Visible = false;
}
}
else
{
}
}
但是 FindControl 不起作用,它找不到那个控件。我在任何时候都错了吗?提前致谢。