UpdatePanel and jQuery are incompatible

Source: Internet
Author: User

During the project, we found that jquery became invalid after partial refreshing when UpdatePanel was used. Later, I checked it online and found that the ready event in jquery will run once after the DOM is fully loaded. When UpdatePanel is used, it only performs partial update and does not Reload all the Dom on the page, therefore, the ready event in jquery will not be executed again. Therefore, we can extract the code executed in the ready event, capture the ScriptManager EndRequest event, and execute a jQuery initialization code after each partial update of UpdatePanel:

// Handle conflicts between ajax and ScriptManager. function load () {Sys. webForms. pageRequestManager. getInstance (). add_endRequest (EndRequestHandler);} function EndRequestHandler () {$ (function () {$ ("tbody "). find ("input: checkbox "). each (function (key, val) {$ (val ). click (function () {var cbxId = $ (this ). attr ("id"); var state = $ (this ). attr ("checked"); $. post ("Ajax/UpdateStatus. ashx ", {" id ": cbxId," isChecked ": state," f Id ":" SamID "}, isReturnStatus) ;}); $ (" thead "). find ("input: checkbox "). click (function () {if (confirm ("are you sure you want to update this column of data? ") = True) {var cbxId = $ (this ). attr ("id"); var name = cbxId. substr (16); var v = "tbody. "+ name +" input [type = 'checkbox'] "; if ($ (this ). attr ("checked") = "checked") {$ (v ). attr ("checked", true);} else {$ (v ). attr ("checked", false);} var state = $ (this ). attr ("checked"); $. post ("Ajax/UpdateStatus. ashx ", {" id ": cbxId," isChecked ": state}, isReturnStatus);} else {if ($ (this ). attr ("checked") = "checked") {$ (this ). attr ("checked", false);} else {$ (this ). attr ("checked", true) ;}}) ;}); initCheckedStaus ();}

 


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.