Jeffz.Web.UpdatePanelIFrameExecutor = function(sourceElement) { Jeffz.Web.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; // the handler to execute when the page in iframe loaded. this._iframeLoadCompleteHandler = Function.createDelegate( this, this._iframeLoadComplete); }
executeRequest : function() { // create an hidden iframe this._iframe = this._createIFrame(); // all the additional hidden input elements this._addAdditionalHiddenElements(); // point the form's target to the iframe this._form.target = this._iframe.id; this._form.encType = "multipart/form-data"; // set up the timeout counter. var timeout = this._webRequest.get_timeout(); if (timeout > 0) { this._timer = window.setTimeout( Function.createDelegate(this, this._onTimeout), timeout); } this._started = true; // restore the status of the element after submitting the form setTimeout(Function.createDelegate(this, this._restoreElements), 0); // sumbit the form this._form.submit(); },
function Sys$WebForms$PageRequestManager$_onFormSubmit(evt) { // ... // Construct the form body var formBody = new Sys.StringBuilder(); formBody.append(this._scriptManagerID + '=' + this._postBackSettings.panelID + '&'); var count = form.elements.length; for (var i = 0; i < count; i++) { // ... // Traverse the input elements to construct the form body // ... } if (if._additionalInput) { formBody.append(this._additionalInput); this._additionalInput = null; } var request = new Sys.Net.WebRequest(); // ... // prepare the web request object // ... var handler = this._get_eventHandlerList().getHandler("initializeRequest"); if (handler) { var eventArgs = new Sys.WebForms.InitializeRequestEventArgs( request, this._postBackSettings.sourceElement); handler(this, eventArgs); continueSubmit = !eventArgs.get_cancel(); } // ... this._request = request; request.invoke(); // ... }
function Sys$WebForms$PageRequestManager$_onFormElementClick(evt) { var element = evt.target; if (element.disabled) { return; } // Check if the element that was clicked on should cause an async postback this._postBackSettings = this._getPostBackSettings(element, element.name); if (element.name) { if (element.tagName === 'INPUT') { var type = element.type; if (type === 'submit') { this._additionalInput = element.name + '=' + encodeURIComponent(element.value); } else if (type === 'image') { var x = evt.offsetX; var y = evt.offsetY; this._additionalInput = element.name + '.x=' + x + '&' + element.name + '.y=' + y; } } else if ((element.tagName === 'BUTTON') && (element.name.length !== 0) && (element.type === 'submit')) { this._additionalInput = element.name + '=' + encodeURIComponent(element.value); } } }
_addAdditionalHiddenElements : function() { var prm = Sys.WebForms.PageRequestManager.getInstance(); // clear the array of hidden input elements this._hiddens = []; // custom sign to indicate an async postback this._addHiddenElement("__AjaxFileUploading__", "__IsInAjaxFileUploading__"); // the value related to the ScriptManager this._addHiddenElement(prm._scriptManagerID, prm._postBackSettings.panelID); // find the additional data var additionalInput = null; var element = this._sourceElement; if (element.name) { var requestBody = this.get_webRequest().get_body(); if (element.tagName === 'INPUT') { var type = element.type; if (type === 'submit') { var index = requestBody.lastIndexOf("&" + element.name + "="); additionalInput = requestBody.substring(index + 1); } else if (type === 'image') { var index = requestBody.lastIndexOf("&" + element.name + ".x="); additionalInput = requestBody.substring(index + 1); } } else if ((element.tagName === 'BUTTON') && (element.name.length !== 0) && (element.type === 'submit')) { var index = requestBody.lastIndexOf("&" + element.name + "="); additionalInput = requestBody.substring(index + 1); } } // parse the additional data if (additionalInput) { var inputArray = additionalInput.split("&"); for (var i = 0; i < inputArray.length; i++) { var nameValue = inputArray[i].split("="); this._addHiddenElement(nameValue[0], decodeURIComponent(nameValue[1])); } } }, _addHiddenElement : function(name, value) { var hidden = document.createElement("input"); hidden.name = name; hidden.value = value; hidden.type = "hidden"; this._form.appendChild(hidden); Array.add(this._hiddens, hidden); },
_iframeLoadComplete : function() { var iframe = this._iframe; delete this._iframe; var responseText = null; try { // ... // retrieve the data we need // ... this._statusCode = 200; this._responseAvailable = true; } catch (e) { this._statusCode = 500; this._responseAvailable = false; } $removeHandler(iframe, "load", this._iframeLoadCompleteHandler); iframe.parentNode.removeChild(iframe); this._clearTimer(); this.get_webRequest().completed(Sys.EventArgs.Empty); },
本文出自 “赵��” 博客,转载请与作者联系!