回调后__doPostBack()? [英] Callback after __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()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!