__doPostBack()后回调?

Bri*_*man 7 asp.net postback updatepanel webforms

我通过调用这样的方法来刷新UpdatePanel和Javscript:

reloadDropDown = function (newValue)
{
  __doPostBack("DropDown1", "");
  selectNewValueInDropDown(newValue);
}
Run Code Online (Sandbox Code Playgroud)

在我的UpdatePanel里面是一个<select>框,我需要<option>newValue选择一个框.我的问题是我的selectNewValueInDropDown方法在__doPostBack完成之前被调用.有没有办法在调用我的selectNewValueInDropDown方法之前"等待"回发?

Mat*_*ley 11

为了使我的评论更具体,这里有一个想法:

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", "");
}
Run Code Online (Sandbox Code Playgroud)

当然,您可能希望处理两个请求重叠的竞争条件.要处理这个问题,您需要跟踪哪个处理程序适合哪个请求.您可以ScriptManager.RegisterDataItem在服务器端使用类似的东西,或者调用args.get_panelsUpdated()并检查您感兴趣的面板是否已更新.


ric*_*ott 6

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
}
Run Code Online (Sandbox Code Playgroud)