开发者

How to check if a checkboxes state has changed

开发者 https://www.devze.com 2022-12-31 05:18 出处:网络
Using .Net, I need to generate a response based 开发者_Python百科on only the checkboxes on my form that have had there states changed. So how do I know if the check box has changed from its previous v

Using .Net, I need to generate a response based 开发者_Python百科on only the checkboxes on my form that have had there states changed. So how do I know if the check box has changed from its previous value before submission. I can't use the onchange event because the user may check multiple boxes before submitting.


Use the event CheckedChanged

check.CheckedChanged += new EventHandler(check_CheckedChanged);
protected void check_CheckedChanged(object sender, EventArgs e)
{
    //do stuff
}


If you compare the previous values with the current values and they are not the same, then they have changed.

So save the previous state into an object, and compare that object with the current state. (recording the changes made gets more complicated as if you change something twice you'd not submit it as a change)


Use the CheckStateChanged (or whatever) event to flag a change (you can store the name in a List, for example), and then use the event from the submit button to save the changes.

0

精彩评论

暂无评论...
验证码 换一张
取 消