Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am refreshing an UpdatePanel with Javscript by calling a method like so:

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

Inside my UpdatePanel is a <select> box that I need to select an <option> with a newValue. My problem is that my selectNewValueInDropDown method is being called prior to the __doPostBack from completing. Is there a way I can "wait" for the postback before calling my selectNewValueInDropDown method?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
676 views
Welcome To Ask or Share your Answers For Others

1 Answer

To make my comment more concrete, here's the idea:

reloadDropDown = function (newValue)
{
    var requestManager = Sys.WebForms.PageRequestManager.getInstance();

    function EndRequestHandler(sender, args) {
        // Here's 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 two requests overlap. To handle that, you would need to keep track of which handler is for which request. You could use something like ScriptManager.RegisterDataItem on the server side, or call args.get_panelsUpdated() and check to see if the panel you're interested it was updated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...