oadPanelIFrameExecutor非常简单,只是定义了一些私有变量:
AspNetAjaxExtensions.UpdatePanelIFrameExecutor = function(sourceElement)
{
AspNetAjaxExtensions.UpdatePanelIFrameExecutor.initializeBase(this);
// for properties
this._started = false;
this._responseAvailable = false;
this._timedOut = false;
this._aborted = false;
this._responseData = null;
this._statusCode = null;
// the element initiated the async postback
this._sourceElement = sourceElement;
// the form in the page.
this._form = Sys.WebForms.PageRequestManager.getInstance()._form;
}
对于大部分属性来说,它们的实现只不过是对上面这些私有变量进行读取或写入而已,在此不提。而一个Executor最重要的莫过于它的executeRequest方法,一些回调函数,还有过期定时器之类的逻辑:
executeRequest : function()
{
this._addAdditionalHiddenElements();
var onSuccess = Function.createDelegate(this, this._onSuccess);
var onFailure = Function.createDelegate(this, this._onFailure);
this._started = true;
var timeout = this._webRequest.get_timeout();
if (timeout > 0)
{
this._timer = window.setTimeout(
Function.createDelegate(this, this._onTimeout), timeout);
}
AspNetAjaxExtensions.UpdatePanelIFrameExecutor._executeForm(
this._form, onSuccess, onFailure);
},
_addAdditionalHiddenElements : function() { },
_removeAdditionalHiddenElements : function() { },
_onSuccess : function(responseData)
{
this._clearTimer();
if (this._aborted || this._timedOut) return;
this._statusCode = 200;
this._responseAvailable = true;
this._responseData = responseData;
this._removeAdditionalHiddenElements();
this.get_webRequest().completed(Sys.EventArgs.Empty);
},
_onFailure : function()
{
this._clearTimer();
if (this._aborted || this._timedOut) return;
this._statusCode = 500;
this._responseAvailable = false;
this._removeAdditionalHiddenElements();
this.get_webRequest().completed(Sys.EventArgs.Empty);
},
abort : function()
{
this._aborted = true;
this._clearTimer();
this._removeAdditionalHiddenElements();
},
_onTimeout : function()
{
this._timedOut = true;
this._statusCode = 500;
this._responseAvailable = false;
this._removeAdditionalHiddenElements();
this.get_webRequest().completed(Sys.EventArgs.Empty);
},
_clearTimer : function()
{
if (this._timer != null)
{
window.clearTimeout(this._timer);
delete this._timer;
}
}
如果您了解Executor的功能,那么应该很容易看懂上面的代码:executeRequest方法用于发出请求,在executeRequest方法中还会打开一个监听是否超时的定时器,当得到回复或超时后就会调用WebRequest的completed方法(在_onSuccess和_onFailure方法内)进行通知。不过上面这段代码中还有两个特别的方法“_addAddtionalHiddenElements”和“removeAdditionalHiddenElements,从名称上就能看出,这是为这次“异步提交”而准备的额外元素。
那么我们该创建哪些附加的隐藏输入元素呢?自然我们表示“异步回送”的自定义标记是其中之一,那么剩下的还需要哪些呢?似乎我们只能通过阅读PageRequestManager的代码来找到问题的答案。还好,似乎阅读下面的代码并不困难:
function Sys$WebForms$PageRequestManager
使UpdatePanel支持上传文件_网学
onFormSubmit(evt)
{
//
// Construct the