简体   繁体   English

控件事件未在ItemTemplate内部触发

[英]Control event not firing inside ItemTemplate

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. 并且在每一行上都有一个复选框,当选中该复选框时,我想更新基础类并设置一个boolean属性。 The problem is that the OnCheckedChanged event is not firing. 问题是OnCheckedChanged事件没有触发。

The ItemTemplate: 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. 最受欢迎的解决方案是设置AutoPostBack =“ true”,我仍然没有。 I'd really appreciate some guidance. 我真的很感谢一些指导。

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 编辑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. 当按下按钮且复选框已更改值时,发生OnCheckedChanged事件。 I guess because the button caused a postback. 我猜是因为该按钮引起了回发。 But why doesn't checkbox cause a postback? 但是,为什么复选框不引起回发? Shouldn't it with AutoPostBack="true"?? 不应该使用AutoPostBack =“ true”吗???

i think your event is wrong. 我认为您的活动有误。

protected void CheckBox1_OnCheckedChanged(object sender, EventArgs e)
{
    //Handle event
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM