[英]ASP.NET Checkbox.Checked is not working
In asp.net Webforms I have a CheckBox
and Button
.在asp.net Webforms 中,我有一个
CheckBox
和Button
。
<asp:CheckBox ID="checkBox" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Check" OnClick="Button1_Click"/>
I want to handle Checkbox
's check status with ButtonClick
.我想用
ButtonClick
处理Checkbox
的检查状态。 But it is only getting false value.但它只会得到错误的价值。
if (checkBox.Checked == (true))
{
Label1.Text = "Selected";
}
else
{
Label1.Text = "Not Selected";
}
After every click
I am getting Not Selected in my Label
.每次
click
后,我的Label
没有被选中。 I think this is so basic but now I couldn't fix.我认为这是非常基本的,但现在我无法修复。
Is there anyway to fix this.有没有办法解决这个问题。
Not sure if this has been solved, this is beacause Autopostback is not enabled.不确定这是否已解决,这是因为未启用 Autopostback。 Change it to below
改为下面
asp:CheckBox ID="checkBox" AutoPostBack=“true” runat="server" ```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.