Callback after __doPostBack ()?

I update UpdatePanel using Javscript by calling a method like this:

reloadDropDown = function (newValue) { __doPostBack("DropDown1", ""); selectNewValueInDropDown(newValue); } 

Inside my UpdatePanel is a <select> field in which I need to select <option> with newValue . My problem is that my selectNewValueInDropDown method selectNewValueInDropDown called before __doPostBack completes. Is there a way to β€œwait” for a postback before calling the selectNewValueInDropDown method?

+6
source share
2 answers

To make my comment more specific, here is an idea:

 reloadDropDown = function (newValue) { var requestManager = Sys.WebForms.PageRequestManager.getInstance(); function EndRequestHandler(sender, args) { // Here where you get to run your code! selectNewValueInDropDown(newValue); requestManager.remove_endRequest(EndRequestHandler); } requestManager.add_endRequest(EndRequestHandler); __doPostBack("DropDown1", ""); } 

Of course, you probably want to handle race conditions where the two requests overlap. To handle this, you will need to keep track of which handler for this request. You can use something like ScriptManager.RegisterDataItem on the server side or call args.get_panelsUpdated() and check if the panel of interest has been updated.

+11
source
 Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler); Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); function BeginRequestHandler(sender, args) { // } function EndRequestHandler(sender, args) { //request is done } 
+6
source

Source: https://habr.com/ru/post/898409/


All Articles