OnCheckedChanged事件不起作用 [英] OnCheckedChanged event doesn't work
本文介绍了OnCheckedChanged事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 asp:CheckBox
和我的ASP.NET页面上的asp:Label
:
< < span class =code-leadattribute> asp:CheckBox ID = checkBox1 runat = server OnCheckedChanged = checkBox1_CheckedChanged < span class =code-attribute> 文本 = 我同意 / > < br / >
< asp:标签 ID = label1 runat = server 文本 = 如果同意,请选中复选框。 / >
我在 asp:CheckBox
中添加了 CheckedChanged
事件处理程序:
protected void checkBox1_CheckedChanged( object sender,EventArgs e)
{
if (!IsPostBack)
{
if (checkBox1.Checked)
{
label1.Text = 你同意。请点击按钮转到下一页。;
}
else
{
label1.Text = 如果您同意,请选中复选框。;
}
}
}
但如果选中/取消选中复选框,标签文字就不会改变。为什么标签文字不会改变,以及如何修复它?
提前致谢。
解决方案
添加''AutoPostback = true
''复选框 - 一旦完成,它应该触发OnCheckedChanged
事件,从而更改标签。
Hi,
I''ve a asp:CheckBox
and a asp:Label
on my ASP.NET page:
<asp:CheckBox ID="checkBox1" runat="server" OnCheckedChanged="checkBox1_CheckedChanged" Text="I agree" /><br />
<asp:Label ID="label1" runat="server" Text="Check the check box if you agree." />
I added a CheckedChanged
event handler to the asp:CheckBox
:
protected void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (checkBox1.Checked)
{
label1.Text = "You agree. Please click on the button to go to the next page.";
}
else
{
label1.Text = "Check the check box if you agree.";
}
}
}
But if I check/uncheck the check box, the label text isn''t changing. Why is the label text not changing, and how to fix it?
Thanks in advance.
解决方案
Add ''AutoPostback = true
'' for the checkbox - once done, it should trigger theOnCheckedChanged
event and thus the label change.
这篇关于OnCheckedChanged事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文