The oncheckedchanged event cannot be triggered by the template column checkbox bound to Asp.net.

Source: Internet
Author: User

The following code is used:

1 <iswebgrid: webgridcolumn caption = "in "inputrequired = "true" name = "title" width = "70px"
2 columntype = "template" datamember = "isshow" edittype = "noedit">
3 <celltemplate>
4 <asp: checkbox runat = "server" id = "cbisshow" Checked = '<% # BIND ("isshow") %> 'enableviewstate = "true"
5 oncheckedchanged = "cbisshow_checkedchanged" enabled = "false"/>
6 </celltemplate>
7 </iswebgrid: webgridcolumn>
1 protected void cbIsShow_CheckedChanged(object sender,EventArgs e)
2 {
3 Response.Write("<script>alert(\"cbIsShow_CheckedChanged\");</script>");
4 }

When you click the checkbox in the template column, the cbisshow_checkedchanged method in the background is always not executed.

Google has many answers, such:

1. autopostback = "true" not written;

2. Set enableviewstate to false;

Not after the test.

After I remove the binding, the cbisshow_checkedchanged method runs normally.

My explanation is:

Oncheckedchanged meets the event trigger condition only after the checked attribute of the checkbox changes. The checked attribute of the checkbox in the template column is bound to the isshow field. without changing the data source, the checked attribute value of the checkbox does not change and does not meet the event trigger conditions. Therefore, it is normal to not run the event processing function.

The possible method is:

1. Add the client event onclicked for the checkbox and call the background method in JS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.