I have a website in which I have a checkout register with dynamically cretaed row for each ordered item. And on each row there is a checkbox and when the checkbox is checked I want to update the underlying class and set the a boolean property. The problem is that the OnCheckedChanged event is not firing.
我有一个网站,我有一个结账注册,每个订购项目都有动态创建的行。并且在每一行上都有一个复选框,当选中该复选框时,我想更新基础类并设置一个布尔属性。问题是OnCheckedChanged事件没有触发。
The ItemTemplate:
<ItemTemplate>
<div>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_OnCheckedChanged"/>
</div>
</ItemTemplate>
The code-behind event:
代码隐藏事件:
protected void CheckBox1_OnCheckedChanged(object sender, EventArgs e)
{
//Handle event
}
I have found a few people with similar problems but none of the solutions I've found have worked. The most popular solution was to set AutoPostBack="true", which I have and still nothing. I'd really appreciate some guidance.
我找到了一些有类似问题的人,但我发现的解决方案都没有。最流行的解决方案是设置AutoPostBack =“true”,我有,但仍然没有。我真的很感激一些指导。
EDIT
I can add that I've now tried using a button in a similar fasion. The buttons OnClick event fires without problem while the checkbox still won't work.
我可以补充一点,我现在尝试使用类似功能的按钮。按钮OnClick事件触发没有问题,而复选框仍然无法工作。
EDIT 2
Just for fun I added a button next to the checkbox which i connected to an empty event. When the button was pressed and the checkbox had changed value the OnCheckedChanged event happened. I guess because the button caused a postback. But why doesn't checkbox cause a postback? Shouldn't it with AutoPostBack="true"??
只是为了好玩,我在复选框旁边添加了一个按钮,我连接到一个空事件。按下按钮并且复选框已更改值时,OnCheckedChanged事件发生。我猜是因为按钮导致了回发。但为什么复选框不会导致回发?不应该用AutoPostBack =“true”吗?
1 个解决方案
#1
0
i think your event is wrong.
我认为你的事件是错的。
protected void CheckBox1_OnCheckedChanged(object sender, EventArgs e)
{
//Handle event
}
#1
0
i think your event is wrong.
我认为你的事件是错的。
protected void CheckBox1_OnCheckedChanged(object sender, EventArgs e)
{
//Handle event
}