简体   繁体   English

复选框事件未触发?

[英]the checkbox event is not triggerd?

i have created checkbox event maually. 我已经创建了复选框事件。

chkCheckBox1.CheckedChanged += new EventHandler(chkCheckBox1_CheckedChanged);

this event is not triggered,in pageload i have put 未触发此事件,在页面加载中

(!page.ispostback)
{
}

so when i clik the check box it goes to the page load and not going to the evnt 因此,当我点击复选框时,它将转到页面加载而不是到evnt

protected void chkCheckBox1_CheckedChanged(object sender, EventArgs e)
{
   ..........  
}

the checkbox event is not triggerd.. 复选框事件未触发。

Have you enabled AutoPostBack property on your control? 您是否在控件上启用了AutoPostBack属性?

By default this is set to False when you add a checkbox control to your page. 默认情况下,当您向页面添加复选框控件时,此选项设置为False。 Try setting it to true. 尝试将其设置为true。

Set the Autopostback property to true . Autopostback属性设置为true

chkCheckBox1.CheckedChanged += new EventHandler(chkCheckBox1_CheckedChanged); chkCheckBox1.CheckedChanged + =新的EventHandler(chkCheckBox1_CheckedChanged);

You have to wire up this event on every call to the page so if you have put this inside of the if(!Page.IsPostBack) then put it outside. 您必须在每次对该页面的调用时都连接此事件,因此,如果将该事件放在if(!Page.IsPostBack)内部,然后将其放置在外部。

Take a look at this article Adding a dynamic control to a placeholder control and wire up the event . 看一下本文, 将动态控件添加到占位符控件并连接事件 It shows an extra step for making things totally dynamic but the principles stay the same for what you're after. 它显示了使事情完全动态化的额外步骤,但原理与您所追求的保持不变。

Grz, Kris. 格里斯,克里斯。

To trigger the following event 触发以下事件

protected void chkCheckBox1_CheckedChanged(object sender, EventArgs e) { .......... 受保护的void chkCheckBox1_CheckedChanged(object sender,EventArgs e){..........
} }

Set the checkbox autopostback property to TRUE 将复选框autopostback属性设置为TRUE

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

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