我有 4 个复选框,每个复选框下方是一个 div。每个复选框负责显示或隐藏其下方的复选框。例如:
<asp:CheckBox ID="CheckBox1" myDiv="divRegisteration" myText=" הרשמה - " runat="server" AutoPostBack="true" Font-Size="18px" Font-Bold="true" Text=" הרשמה - הצג" OnCheckedChanged="CheckBox_CheckedChanged"/>
<div id="divRegisteration" runat="server" visible="false">
复选框“CheckBox1”负责显示或隐藏 div“divRegisteration”,它在自定义属性“myDiv”中得到解决。
问题是,在后面的代码中,它没有找到属性“myDiv”:
if (((CheckBox)(sender)).Checked==true)
{
CheckBox chk = (CheckBox)(sender);
object div = FindControl(chk.Attributes["myDiv"]); //// it does not find myDiv, and therefore doesn't find the control so the program crashes.
HtmlGenericControl addressDiv = (HtmlGenericControl)(div);
addressDiv.Visible = true;
}