如果选中上面的复选框,我试图取消隐藏一组单选按钮,并在未选中复选框时隐藏它们。我在同一个应用程序中有一个以前的版本,它工作得很好[单选按钮打开复选框]而不是在工作一个。选择MinorCheck
时,单选按钮不可见。没有错误显示,没有任何反应。为什么是这样?
我看过其他评论Visible =“false”如何阻止它等等。但是,很明显,开头的visible =“false”对我的第一个编码块来说不是问题。
我使用的一个参考:ASP.NET CheckBox does not fire CheckedChanged event when unchecking
工作一:
HTML
<td class="LeftAlign" width="24%">
<font class="Blackfont" size="1">
<B> Union Affiliated?
</B>
</font>
<font class="WeOrangefont" size="1">
•
</font>
</td>
<td width="10%">
<asp:RadioButtonList ID="rblclass" runat="server" AutoPostBack="True" class="Bluefont" size="1" font-Bold="True" font-Size="8pt" >
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:RadioButtonList>
</td>
<td></td>
</tr>
</table>
VB.NET
Protected Sub rblclass_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblclass.SelectedIndexChanged
If (rblclass.SelectedValue = "Y") Then
Register.Focus()
union1.Visible = True
union2.Visible = True
union3.Visible = True
LocalLbl.Visible = True
Reqimage.Visible = True
Else
Register.Focus()
union1.Visible = False
union2.Visible = False
union3.Visible = False
LocalLbl.Visible = False
Reqimage.Visible = False
End If
End Sub
编码的其他部分即使非常相似也不起作用:
<tr>
<td class="LeftAlign" colspan="2">
<font class="Blackfont" size="1">
<asp:CheckBox ID="MinorCheck" runat="server" NAME="BUSINESSCLASSIFICATION"
class="ownerClass" value="000" checked = "false" TabIndex="32"/>
<asp:HyperLink ID="HyperLink2" runat="server" TABSTOP = "-1" onClick="OpenWindow('Images/Supp.html', 'Min Business Concern',600, 300, 'no')" font-Underline="True" ForeColor="#666666" >Minority Business Concern</asp:HyperLink>
</font>
</td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="RadioButtonBClass" runat="server" AutoPostBack="True"
class="Bluefont" size="1" font-Bold="True" font-Size="8pt" visible = "false">
<asp:ListItem Value="Y" >African-American male</asp:ListItem>
<asp:ListItem Value="N">African-American female</asp:ListItem>
<asp:ListItem Value="N">Asian-Indian American male</asp:ListItem>
<asp:ListItem Value="N">Asian-Indian American female</asp:ListItem>
<asp:ListItem Value="N">Asian-Pacific American male</asp:ListItem>
<asp:ListItem Value="N">Asian-Pacific American female</asp:ListItem>
<asp:ListItem Value="N">Native American male</asp:ListItem>
<asp:ListItem Value="N">Native American female</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
VB.NET
Protected Sub MinorCheck_CheckedChanged(sender As Object, e As EventArgs) Handles MinorCheck.CheckedChanged
If (MinorCheck.Checked = true) Then
RadioButtonBClass.Visible = True
NonMinorCheck.Checked = false
Else
RadioButtonBClass.Visible = False
End If
End Sub
答案 0 :(得分:1)
令人困惑但是当您在ASP控件中使用属性Visible时,实际上根本不创建对象,所以如果您尝试更改为Visible,则无法正常工作,我个人使用的是一个技巧一个CSS类,我将复制我为你的案例制作的代码:
<style>
.CSSHiden {
display: none;
}
</style>
注意:我在Checkbox次要检查中设置了Autopostback = true
<asp:CheckBox ID="MinorCheck" runat="server" NAME="BUSINESSCLASSIFICATION"
class="ownerClass" value="000" TabIndex="32" OnCheckedChanged="MinorCheck_CheckedChanged" AutoPostBack="True"/>
<asp:HyperLink ID="HyperLink2" runat="server" TABSTOP = "-1" onClick="OpenWindow('Images/Supp.html', 'Min Business Concern',600, 300, 'no')" font-Underline="True" ForeColor="#666666" >Minority Business Concern</asp:HyperLink>
<asp:RadioButtonList ID="RadioButtonBClass" runat="server" AutoPostBack="True" class="Bluefont" size="1" font-Bold="True" font-Size="8pt" CssClass="CSSHiden">
<asp:ListItem Value="Y" >African-American male</asp:ListItem>
<asp:ListItem Value="N">African-American female</asp:ListItem>
<asp:ListItem Value="N">Asian-Indian American male</asp:ListItem>
<asp:ListItem Value="N">Asian-Indian American female</asp:ListItem>
<asp:ListItem Value="N">Asian-Pacific American male</asp:ListItem>
<asp:ListItem Value="N">Asian-Pacific American female</asp:ListItem>
<asp:ListItem Value="N">Native American male</asp:ListItem>
<asp:ListItem Value="N">Native American female</asp:ListItem>
</asp:RadioButtonList>
我使用的代码是c#,但更改为VB.net非常简单
protected void MinorCheck_CheckedChanged(object sender, EventArgs e)
{
if (MinorCheck.Checked == true)
RadioButtonBClass.CssClass = "";
else
RadioButtonBClass.CssClass = "CSSHiden";
}
答案 1 :(得分:1)
您的复选框缺少AutotPostBack=True
。没有它,CheckedChanged
事件将不会触发,直到其他控件执行PostBack
。