Interaction between user js and ASP. NETUpdatePanel controls

Source: Internet
Author: User
Interaction between user js and ASP. NETUpdatePanel controls: Call js after UpdatePanel update is complete. Use js to activate UpdatePanel update. First, call js after UpdatePanel update is complete. Key code: Sys. WebForms. PageRequestM...

Interaction between user js and ASP. NET UpdatePanel controls:

Call js after UpdatePanel is updated.
Use js to activate UpdatePanel update

First, the content used by today's code: Call js after UpdatePanel is updated.

 

Key code: Sys. WebForms. PageRequestManager. getInstance (). add_endRequest (AddTextBoxFouce );

Cause:

I used JQuery to design a piece of code, $ (). ready (page Load completed, that is, $ (document ). after ready), run AddTextBoxFouce () to give some TextBox controls (the corresponding HTML is) Is bound to a blur event. The specific function is to enter a value in some text boxes, and a corresponding box is also changed. Some enter "-1" and others change to "+ 1 "; some input "2", and the other one also changes to "2 ".

$ (). Ready (function (){
AddTextBoxFouce ();
});

However, during the test today, we found that after UpdatePanel is updated, the bound blur event on the text box contained in UpdatePanel is gone! After the page is loaded, all $ (). ready () is run, and the corresponding text box is bound with The blur event. This part of the design is correct. The problem may be that after UpdatePanel is updated, the content dom included in the UpdatePanel control has been replaced again. The text boxes in these dom are not bound to The blur event.

 

After carefully checking and determining the cause, we thought of A solution: Solution A, that is, adding "onclick" to the button that triggers UpdatePanel update; solution B, on the UpdatePanel update trigger event, add code and call AddTextBoxFouce () again ().


Solution A: Add "onclick" on the button, which involves the sequence of event triggering and ASP.. net ajax script conflicts with JQuery (JQuery can clear all events on the dom ). Due to the time relationship, a simple test was conducted while writing this article. The result is to first stimulate the common "onclick" of the client ", then submit the update (it may be a delay in submitting to the server and then returning the approval, but it also makes no sense ).


Solution B needs to study UpdatePanel event excitation (in fact, ScriptManager event excitation ). This original research has been vague for a long time. Fortunately, today we are "very lucky" and soon found several powerful blogs. I found the relevant code and added it to the page for testing twice. The problem was solved.
Note that the Sys. WebForms. PageRequestManager. getInstance (). add_endRequest (AddTextBoxFouce) statement must be placed in .

 

Then, use js to activate UpdatePanel update.


Solution 1: Use a hidden Button for triggering.
Solution 2: __dopostback ('panelname ','');
In addition, I tried to find a class library similar to Sys. WebForms. PageRequestManager for implementation. The result is not found yet.

 

Author: Bangle

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.