Solution to the conflict between Ajax and JQuery's ready functions in Asp.net

Source: Internet
Author: User

The combination of Asp.net Ajax and Asp.net is perfect, and Jquery is inevitable when it is not enough. Jquery and Asp.net Ajax are also common in combination. If they are well handled, they will not conflict with each other. However, it was recently found that when Jquery's ready () function came back from PostBack, the action executed in ready was actually invalid. First impression: will Asp.net Ajax conflict with Jqueryd's ready, then remove the Asp.net Ajax script reference, and everything is normal. After thinking about it, I finally added add_endRequest () to Asp.net Ajax ScriptManager, and Jquery's ready finally got back to normal.

The code is as follows: Copy code

<Script type = "text/javascript">
Sys. WebForms. PageRequestManager. getInstance ()
. Add_endRequest (EndRequestHandler );
   
Function EndRequestHandler (sender, args ){
If (args. get_error () = undefined ){
PageInit ();
        }
    }

Function PageInit (){
$ (Document). ready (function (){
// TODO
});
    }

PageInit ();
</Script>

Add the above code and pay attention to it. If this script is placed in the head, an error will occur, prompting the Sys object undefined, because the ScriptManager of Asp.net Ajax, if the state is not complete, the Sys object cannot be found, and the script is placed at the end of the body, everything is normal.

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.