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 bind a blur event to some TextBox controls (the corresponding HTML is <input type = "text"/>. 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 statement Sys. WebForms. PageRequestManager. getInstance (). add_endRequest (AddTextBoxFouce) must be placed behind <asp: ScriptManager>.
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