__doPostBack()之后的回调?

发布于 2024-12-07 05:25:10 字数 385 浏览 1 评论 0原文

我通过调用如下方法使用 Javscript 刷新 UpdatePanel:

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

在我的 UpdatePanel 内部有一个

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守护在此方 2024-12-14 05:25:10

为了使我的评论更具体,我的想法是:

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", "");
}

当然,您可能想要处理两个请求重叠的竞争条件。为了处理这个问题,您需要跟踪哪个处理程序针对哪个请求。您可以在服务器端使用诸如 ScriptManager.RegisterDataItem 之类的内容,或者调用 args.get_panelsUpdated() 并检查您感兴趣的面板是否已更新。

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.

苯莒 2024-12-14 05:25:10
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
}
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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文