Callback after __doPostBack()?(__doPostBack() 之后的回调?)
问题描述
我正在通过调用如下方法使用 Javscript 刷新 UpdatePanel:
I am refreshing an UpdatePanel with Javscript by calling a method like so:
reloadDropDown = function (newValue)
{
__doPostBack("DropDown1", "");
selectNewValueInDropDown(newValue);
}
在我的 UpdatePanel 内是一个 框,我需要选择一个 和 newValue.我的问题是我的 selectNewValueInDropDown 方法在 __doPostBack 完成之前被调用.有没有办法在调用我的 selectNewValueInDropDown 方法之前等待"回发?
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?
推荐答案
为了让我的评论更具体,这里的想法是:
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", "");
}
当然,您可能希望处理两个请求重叠的竞争条件.要处理它,您需要跟踪哪个处理程序针对哪个请求.您可以在服务器端使用类似 ScriptManager.RegisterDataItem 的东西,或调用 args.get_panelsUpdated() 并检查您感兴趣的面板是否已更新.
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.
这篇关于__doPostBack() 之后的回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:__doPostBack() 之后的回调?
基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
