/Client/MicrosoftAjax/Extensions/Sys/WebForms/PageRequestManager.js
JavaScript | 1261 lines | 836 code | 122 blank | 303 comment | 204 complexity | 7d45dffe4d6be8c33533d81cbd324317 MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- $type = Sys.WebForms.PageRequestManager = function PageRequestManager() {
- this._form = null;
- this._activeDefaultButton = null;
- this._activeDefaultButtonClicked = false;
- this._updatePanelIDs = null;
- this._updatePanelClientIDs = null;
- this._updatePanelHasChildrenAsTriggers = null;
- this._asyncPostBackControlIDs = null;
- this._asyncPostBackControlClientIDs = null;
- this._postBackControlIDs = null;
- this._postBackControlClientIDs = null;
- this._scriptManagerID = null;
- this._pageLoadedHandler = null;
-
- this._additionalInput = null;
- this._onsubmit = null;
- this._onSubmitStatements = [];
- this._originalDoPostBack = null;
- this._originalDoPostBackWithOptions = null;
- this._originalFireDefaultButton = null;
- this._originalDoCallback = null;
- this._isCrossPost = false;
- this._postBackSettings = null;
- this._request = null;
- this._onFormSubmitHandler = null;
- this._onFormElementClickHandler = null;
- this._onWindowUnloadHandler = null;
- this._asyncPostBackTimeout = null;
-
- this._controlIDToFocus = null;
- this._scrollPosition = null;
- this._processingRequest = false;
- this._scriptDisposes = {};
-
- // DevDiv Bugs 161922, 138251:
- // List of hidden fields that should be removed if an async update does not
- // explictly define it.
- this._transientFields = ["__VIEWSTATEENCRYPTED", "__VIEWSTATEFIELDCOUNT"];
- }
-
- $type.prototype = {
- get_isInAsyncPostBack: function PageRequestManager$get_isInAsyncPostBack() {
- /// <value type="Boolean" locid="P:J#Sys.WebForms.PageRequestManager.isInAsyncPostBack"></value>
- //#if DEBUG
- if (arguments.length !== 0) throw Error.parameterCount();
- //#endif
- return this._request !== null;
- },
-
- // Events
- add_beginRequest: function PageRequestManager$add_beginRequest(handler) {
- /// <summary locid="E:J#Sys.WebForms.PageRequestManager.beginRequest">Adds a beginRequest event handler.</summary>
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.addEventHandler(this, "beginRequest", handler);
- },
- remove_beginRequest: function PageRequestManager$remove_beginRequest(handler) {
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.removeEventHandler(this, "beginRequest", handler);
- },
-
- add_endRequest: function PageRequestManager$add_endRequest(handler) {
- /// <summary locid="E:J#Sys.WebForms.PageRequestManager.endRequest">Adds a endRequest event handler.</summary>
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.addEventHandler(this, "endRequest", handler);
- },
- remove_endRequest: function PageRequestManager$remove_endRequest(handler) {
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.removeEventHandler(this, "endRequest", handler);
- },
-
- add_initializeRequest: function PageRequestManager$add_initializeRequest(handler) {
- /// <summary locid="E:J#Sys.WebForms.PageRequestManager.initializeRequest">Adds a initializeRequest event handler.</summary>
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.addEventHandler(this, "initializeRequest", handler);
- },
- remove_initializeRequest: function PageRequestManager$remove_initializeRequest(handler) {
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.removeEventHandler(this, "initializeRequest", handler);
- },
-
- add_pageLoaded: function PageRequestManager$add_pageLoaded(handler) {
- /// <summary locid="E:J#Sys.WebForms.PageRequestManager.pageLoaded">Adds a pageLoaded event handler.</summary>
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.addEventHandler(this, "pageLoaded", handler);
- },
- remove_pageLoaded: function PageRequestManager$remove_pageLoaded(handler) {
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.removeEventHandler(this, "pageLoaded", handler);
- },
-
- add_pageLoading: function PageRequestManager$add_pageLoading(handler) {
- /// <summary locid="E:J#Sys.WebForms.PageRequestManager.pageLoading">Adds a pageLoading event handler.</summary>
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.addEventHandler(this, "pageLoading", handler);
- },
- remove_pageLoading: function PageRequestManager$remove_pageLoading(handler) {
- //#if DEBUG
- var e = Function._validateParams(arguments, [{name: "handler", type: Function}]);
- if (e) throw e;
- //#endif
- Sys.Observer.removeEventHandler(this, "pageLoading", handler);
- },
-
- abortPostBack: function PageRequestManager$abortPostBack() {
- if (!this._processingRequest && this._request) {
- // cancel the request if a response hasn't already been received
- this._request.get_executor().abort();
- this._request = null;
- }
- },
-
- beginAsyncPostBack: function PageRequestManager$beginAsyncPostBack(updatePanelsToUpdate, eventTarget, eventArgument, causesValidation, validationGroup) {
- /// <summary locid="M:J#Sys.WebForms.PageRequestManager.beginAsyncPostBack">Begins an asynchronous postback.</summary>
- /// <param name="updatePanelsToUpdate" type="Array" elementType="String" mayBeNull="true" optional="true">A list of UniqueIDs or ClientIDs of UpdatePanel controls that should have their rendering updated.</param>
- /// <param name="eventTarget" type="String" mayBeNull="true" optional="true"></param>
- /// <param name="eventArgument" type="String" mayBeNull="true" optional="true"></param>
- /// <param name="causesValidation" type="Boolean" mayBeNull="true" optional="true"></param>
- /// <param name="validationGroup" type="String" mayBeNull="true" optional="true"></param>
- //#if DEBUG
- var e = Function._validateParams(arguments, [
- {name: "updatePanelsToUpdate", type: Array, mayBeNull: true, optional: true, elementType: String},
- {name: "eventTarget", type: String, mayBeNull: true, optional: true},
- {name: "eventArgument", type: String, mayBeNull: true, optional: true},
- {name: "causesValidation", type: Boolean, mayBeNull: true, optional: true},
- {name: "validationGroup", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- //#endif
- if (causesValidation && (typeof(Page_ClientValidate) === 'function') && !Page_ClientValidate(validationGroup || null)) {
- return;
- }
- this._postBackSettings = this._createPostBackSettings(true, updatePanelsToUpdate, eventTarget);
- var form = this._form;
- form.__EVENTTARGET.value = (eventTarget || "");
- form.__EVENTARGUMENT.value = (eventArgument || "");
- this._isCrossPost = false;
- this._additionalInput = null;
- this._onFormSubmit();
- },
-
- _cancelPendingCallbacks: function PageRequestManager$_cancelPendingCallbacks() {
- // DevDiv Bugs 125825: To avoid EVENTVALIDATION corruption we must cancel pending callbacks when an async postback begins
- // to cancel callbacks, we run logic similar to WebForm_CallbackComplete,
- // except we do not run WebForm_ExecuteCallback for them. This code is exactly
- // WebForm_CallbackComplete except without the call to WebForm_ExecuteCallback.
- // We are basically treating each callback as completed, ignoring the response if any.
- for (var i = 0, l = window.__pendingCallbacks.length; i < l; i++) {
- var callback = window.__pendingCallbacks[i];
- if (callback) {
- if (!callback.async) {
- // we just cancelled the single allowed instance of a synchronous callback
- window.__synchronousCallBackIndex = -1;
- }
- window.__pendingCallbacks[i] = null;
- var callbackFrameID = "__CALLBACKFRAME" + i;
- var xmlRequestFrame = document.getElementById(callbackFrameID);
- if (xmlRequestFrame) {
- xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);
- }
- }
- }
- },
-
- _commitControls: function PageRequestManager$_commitControls(updatePanelData, asyncPostBackTimeout) {
- // DevDiv Bugs 154403:
- // commits context data parsed from a delta. This is called after an async response
- // has proceeded past the script include loading phase, which when it can no longer
- // be cancelled and the HTML DOM will be updated.
- // _processUpdatePanelArrays is the method that creates these arrays..
- // DevDiv Bugs 188564: Update may not have an async postback timeout node and/or updatepanel nodes.
- if (updatePanelData) {
- this._updatePanelIDs = updatePanelData.updatePanelIDs;
- this._updatePanelClientIDs = updatePanelData.updatePanelClientIDs;
- this._updatePanelHasChildrenAsTriggers = updatePanelData.updatePanelHasChildrenAsTriggers;
- this._asyncPostBackControlIDs = updatePanelData.asyncPostBackControlIDs;
- this._asyncPostBackControlClientIDs = updatePanelData.asyncPostBackControlClientIDs;
- this._postBackControlIDs = updatePanelData.postBackControlIDs;
- this._postBackControlClientIDs = updatePanelData.postBackControlClientIDs;
- }
- if (typeof(asyncPostBackTimeout) !== 'undefined' && asyncPostBackTimeout !== null) {
- this._asyncPostBackTimeout = asyncPostBackTimeout * 1000;
- }
- },
-
- _createHiddenField: function PageRequestManager$_createHiddenField(id, value) {
- // DevDiv Bugs 27075: Creates a hidden field via innerHTML to workaround a caching issue.
- var container, field = document.getElementById(id);
-
- if (field) {
- // the field already exists
- if (!field._isContained) {
- // but it is not contained within a SPAN container, so we must create one
- // in order to recreate it with innerHTML.
- field.parentNode.removeChild(field);
- }
- else {
- // and it already has a container, we'll just set the container innerHTML to replace it,
- // which is much faster than removing the element, recreating it, and then setting innerHTML
- container = field.parentNode;
- }
- }
- if (!container) {
- container = document.createElement('span');
- // set display none in case this SPAN would be styled
- container.style.cssText = "display:none !important";
- this._form.appendChild(container);
- }
- // now create/replace the input by setting innerHTML
- container.innerHTML = "<input type='hidden' />";
- field = container.childNodes[0];
- // flag it as contained, so if it needs to be removed we know to remove the container, too.
- field._isContained = true;
- field.id = field.name = id;
- field.value = value;
- },
-
- _createPageRequestManagerTimeoutError: function PageRequestManager$_createPageRequestManagerTimeoutError() {
- // Creates a PageRequestManagerTimeoutException representing a request that timed out.
- var displayMessage = "Sys.WebForms.PageRequestManagerTimeoutException: " + Sys.WebForms.Res.PRM_TimeoutError;
- var e = Error.create(displayMessage, {name: 'Sys.WebForms.PageRequestManagerTimeoutException'});
- e.popStackFrame();
- return e;
- },
-
- _createPageRequestManagerServerError: function PageRequestManager$_createPageRequestManagerServerError(httpStatusCode, message) {
- // Creates a PageRequestManagerServerErrorException representing an error that occurred on the server.
- var displayMessage = "Sys.WebForms.PageRequestManagerServerErrorException: " +
- (message || String.format(Sys.WebForms.Res.PRM_ServerError, httpStatusCode));
- var e = Error.create(displayMessage, {
- name: 'Sys.WebForms.PageRequestManagerServerErrorException',
- httpStatusCode: httpStatusCode
- });
- e.popStackFrame();
- return e;
- },
-
- _createPageRequestManagerParserError: function PageRequestManager$_createPageRequestManagerParserError(parserErrorMessage) {
- // Creates a PageRequestManagerParserErrorException representing a parser error that occurred while processing a response from the server.
- var displayMessage = "Sys.WebForms.PageRequestManagerParserErrorException: " + String.format(Sys.WebForms.Res.PRM_ParserError, parserErrorMessage);
- var e = Error.create(displayMessage, {name: 'Sys.WebForms.PageRequestManagerParserErrorException'});
- e.popStackFrame();
- return e;
- },
-
- _createPanelID: function PageRequestManager$_createPanelID(panelsToUpdate, postBackSettings) {
- var asyncTarget = postBackSettings.asyncTarget,
- toUpdate = this._ensureUniqueIds(panelsToUpdate || postBackSettings.panelsToUpdate),
- panelArg = (toUpdate instanceof Array)
- ? toUpdate.join(',')
- : (toUpdate || this._scriptManagerID);
- if (asyncTarget) {
- panelArg += "|" + asyncTarget;
- }
- return encodeURIComponent(this._scriptManagerID) + '=' + encodeURIComponent(panelArg) + '&';
- },
-
- _createPostBackSettings: function PageRequestManager$_createPostBackSettings(async, panelsToUpdate, asyncTarget, sourceElement) {
- return { async:async, asyncTarget: asyncTarget, panelsToUpdate: panelsToUpdate, sourceElement: sourceElement };
- },
-
- _convertToClientIDs: function PageRequestManager$_convertToClientIDs(source, destinationIDs, destinationClientIDs, version4) {
- if (source) {
- for (var i = 0, l = source.length; i < l; i += (version4 ? 2 : 1)) {
- var uniqueID = source[i],
- clientID = (version4 ? source[i+1] : "") || this._uniqueIDToClientID(uniqueID);
- Array.add(destinationIDs, uniqueID);
- Array.add(destinationClientIDs, clientID);
- }
- }
- },
-
- dispose: function PageRequestManager$dispose() {
- Sys.Observer.clearEventHandlers(this);
- if (this._form) {
- Sys.UI.DomEvent.removeHandler(this._form, 'submit', this._onFormSubmitHandler);
- Sys.UI.DomEvent.removeHandler(this._form, 'click', this._onFormElementClickHandler);
- Sys.UI.DomEvent.removeHandler(window, 'unload', this._onWindowUnloadHandler);
- Sys.UI.DomEvent.removeHandler(window, 'load', this._pageLoadedHandler);
- }
-
- if (this._originalDoPostBack) {
- window.__doPostBack = this._originalDoPostBack;
- this._originalDoPostBack = null;
- }
- if (this._originalDoPostBackWithOptions) {
- window.WebForm_DoPostBackWithOptions = this._originalDoPostBackWithOptions;
- this._originalDoPostBackWithOptions = null;
- }
- if (this._originalFireDefaultButton) {
- window.WebForm_FireDefaultButton = this._originalFireDefaultButton;
- this._originalFireDefaultButton = null;
- }
- if (this._originalDoCallback) {
- window.WebForm_DoCallback = this._originalDoCallback;
- this._originalDoCallback = null;
- }
-
- this._form = null;
- this._updatePanelIDs = null;
- this._updatePanelClientIDs = null;
- this._asyncPostBackControlIDs = null;
- this._asyncPostBackControlClientIDs = null;
- this._postBackControlIDs = null;
- this._postBackControlClientIDs = null;
- this._asyncPostBackTimeout = null;
- this._scrollPosition = null;
- },
-
- _doCallback: function PageRequestManager$_doCallback(eventTarget, eventArgument, eventCallback, context, errorCallback, useAsync) {
- // DevDiv Bugs 125825: Do not allow callbacks to begin while an async postback is in progress to prevent EVENTVALIDATION corruption
- if (!this.get_isInAsyncPostBack()) {
- this._originalDoCallback(eventTarget, eventArgument, eventCallback, context, errorCallback, useAsync);
- }
- },
-
- // New implementation of __doPostBack
- _doPostBack: function PageRequestManager$_doPostBack(eventTarget, eventArgument) {
- this._additionalInput = null;
-
- var form = this._form;
- if ((eventTarget === null) || (typeof(eventTarget) === "undefined") || (this._isCrossPost)) {
- // Allow the default form submit to take place. Since it's a cross-page postback.
- // DevDiv 80942: we should fall to a full postback if event target is null or undefined
- this._postBackSettings = this._createPostBackSettings(false);
- // set to false so subsequent posts that don't go through DPWO aren't considered cross post
- this._isCrossPost = false;
- }
- else {
- var mpUniqueID = this._masterPageUniqueID;
- // If it's not a cross-page post, see if we can find the DOM element that caused the postback
- var clientID = this._uniqueIDToClientID(eventTarget);
- var postBackElement = document.getElementById(clientID);
- if (!postBackElement && mpUniqueID) {
- if (clientID.indexOf(mpUniqueID + "$") === 0) {
- // With ClientIDMode=Predictable, the MasterPageID is missing from the beginning
- // of the client ID.
- postBackElement = document.getElementById(clientID.substr(mpUniqueID.length + 1));
- }
- }
- if (!postBackElement) {
- // If the control has no matching DOM element we look for an exact
- // match from RegisterAsyncPostBackControl or RegisterPostBackControl.
- // If we can't find anything about it then we do a search based on
- // naming containers to still try and find a match.
- if (Array.contains(this._asyncPostBackControlIDs, eventTarget)) {
- // Exact match for async postback
- this._postBackSettings = this._createPostBackSettings(true, null, eventTarget);
- }
- else {
- if (Array.contains(this._postBackControlIDs, eventTarget)) {
- // Exact match for regular postback
- this._postBackSettings = this._createPostBackSettings(false);
- }
- else {
- // Find nearest element based on UniqueID in case the element calling
- // __doPostBack doesn't have an ID. GridView does this for its Update
- // button and without this we can't do async postbacks.
- var nearestUniqueIDMatch = this._findNearestElement(eventTarget);
- if (nearestUniqueIDMatch) {
- // We found a related parent element, so walk up the DOM to find out what kind
- // of postback we should do.
- this._postBackSettings = this._getPostBackSettings(nearestUniqueIDMatch, eventTarget);
- }
- else {
- // the control may have rendered without the master page id prefix due to ClientIDMode = Predictable
- // For example "ctl00$ctl00$foo$Button1" may have rendered an id of "foo_button1" if "ctl00$ctl00"
- // is the ID for a 2-level nested master page.
- // try stripping it from the beginning of the ID and trying again
- if (mpUniqueID) {
- mpUniqueID += "$";
- if (eventTarget.indexOf(mpUniqueID) === 0) {
- nearestUniqueIDMatch = this._findNearestElement(eventTarget.substr(mpUniqueID.length));
- }
- }
- if (nearestUniqueIDMatch) {
- // We found a related parent element, so walk up the DOM to find out what kind
- // of postback we should do.
- this._postBackSettings = this._getPostBackSettings(nearestUniqueIDMatch, eventTarget);
- }
- else {
- // Can't find any DOM element at all related to the eventTarget,
- // so we just give up and do a regular postback.
- this._postBackSettings = this._createPostBackSettings(false);
- }
- }
- }
- }
- }
- else {
- // The element was found, so walk up the DOM to find out what kind
- // of postback we should do.
- this._postBackSettings = this._getPostBackSettings(postBackElement, eventTarget);
- }
- }
-
- if (!this._postBackSettings.async) {
- // Temporarily restore the form's onsubmit handler expando while calling
- // the original ASP.NET 2.0 __doPostBack() function.
- form.onsubmit = this._onsubmit;
- this._originalDoPostBack(eventTarget, eventArgument);
- form.onsubmit = null;
- return;
- }
-
- form.__EVENTTARGET.value = eventTarget;
- form.__EVENTARGUMENT.value = eventArgument;
- this._onFormSubmit();
- },
-
- _doPostBackWithOptions: function PageRequestManager$_doPostBackWithOptions(options) {
- this._isCrossPost = options && options.actionUrl;
- // note that when DoPostBackWithOptions is used, _doPostBack or _onFormSubmit, one of the two,
- // are guaranteed to be called next.
- // In both of those methods it is important to clear the isCrossPost flag so subsequent posts that
- // don't use DoPostBackWithOptions are not considered cross page posts.
- this._originalDoPostBackWithOptions(options);
- },
-
- _elementContains: function PageRequestManager$_elementContains(container, element) {
- while (element) {
- if (element === container) {
- return true;
- }
- element = element.parentNode;
- }
- return false;
- },
-
- _endPostBack: function PageRequestManager$_endPostBack(error, executor, data) {
- if (this._request === executor.get_webRequest()) {
- // the postback being ended is the one being processed
- this._processingRequest = false;
- this._additionalInput = null;
- this._request = null;
- }
-
- var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);
- Sys.Observer.raiseEvent(this, "endRequest", eventArgs);
- if (error && !eventArgs.get_errorHandled()) {
- // DevDiv 89485: throw, don't alert()
- throw error;
- }
- },
-
- _ensureUniqueIds: function PageRequestManager$_ensureUniqueIds(ids) {
- // given a single ID or an array of IDs that might be ClientIDs or UniqueIDs,
- // returns a list of the UniqueIDs. This is used from createPanelID and makes
- // it so beginAsyncPostBack and the panelstoUpdate property of the event args
- // supports a list of update panels by UniqueID or ClientID.
- // If an ID is not a ClientID we assume it is a UniqueID even though it could just be
- // that it does not exist.
- if (!ids) return ids;
- ids = ids instanceof Array ? ids : [ids];
- var uniqueIds = [];
- for (var i = 0, l = ids.length; i < l; i++) {
- var id = ids[i], index = Array.indexOf(this._updatePanelClientIDs, id);
- uniqueIds.push(index > -1 ? this._updatePanelIDs[index] : id);
- }
- return uniqueIds;
- },
-
- // Finds the nearest element to the given UniqueID. If an element is not
- // found for the exact UniqueID, it walks up the parent chain to look for it.
- _findNearestElement: function PageRequestManager$_findNearestElement(uniqueID) {
- while (uniqueID.length > 0) {
- var clientID = this._uniqueIDToClientID(uniqueID);
- var element = document.getElementById(clientID);
- if (element) {
- return element;
- }
- var indexOfLastDollar = uniqueID.lastIndexOf('$');
- if (indexOfLastDollar === -1) {
- return null;
- }
- uniqueID = uniqueID.substring(0, indexOfLastDollar);
- }
- return null;
- },
-
- _findText: function PageRequestManager$_findText(text, location) {
- var startIndex = Math.max(0, location - 20);
- var endIndex = Math.min(text.length, location + 20);
- return text.substring(startIndex, endIndex);
- },
-
- _fireDefaultButton: function PageRequestManager$_fireDefaultButton(event, target) {
- // This is a copy of the function WebForm_FireDefaultButton as defined in WebForms.js.
- // The purpose is to hook into the WebForm_FireDefaultButton call with the code commented in the middle.
- // Other than that, there have been a few minor changes to the code but the logic is the same.
- if (event.keyCode === 13) {
- var src = event.srcElement || event.target;
- if (!src || (src.tagName.toLowerCase() !== "textarea")) {
- var defaultButton = document.getElementById(target);
-
- if (defaultButton && (typeof(defaultButton.click) !== "undefined")) {
-
- // Beginning of new code...
-
- // In all but FF this causes the form.onclick event to fire with the button as the event target.
- // In FF the the form.onclick event has the current focus control as the target, which prevents the
- // default button's server-side click event from firing. So we ensure the correct control is determined
- // to have caused the postback by saving the default button before clicking on it. The code in
- // onFormSubmit looks for this field and ensures the postback target is the button.
- this._activeDefaultButton = defaultButton;
- this._activeDefaultButtonClicked = false;
- try {
- // click is synchronous -- it will immediately cause a form onclick event and then a form onsubmit event
- // assuming nothing uses preventDefault() to cancel the event.
- defaultButton.click();
- }
- finally {
- // form submission may or may not be occuring after this point
- this._activeDefaultButton = null;
- }
-
- // ...End of new code
-
- // cancel submission caused by hitting enter in the input control
- event.cancelBubble = true;
- if (typeof(event.stopPropagation) === "function") {
- event.stopPropagation();
- }
- return false;
- }
- }
- }
- return true;
- },
-
- _getPageLoadedEventArgs: function PageRequestManager$_getPageLoadedEventArgs(initialLoad, data) {
- // -------------+------------------------------------+-----------------------
- // Situation | In ID collections | In eventArg property
- // -------------+------------------------------------+-----------------------
- // Update (exp) | in panelsToRefresh | updated
- // Update (imp) | in new, in old, in childUP | created
- // Create (exp) | in new, not in old, not in childUP | created
- // Create (imp) | in new, not in old, in childUP | created
- // Delete (exp) | not in new, in old, not in childUP | ---
- // Delete (imp) | not in new, in old, in childUP | ---
- // -------------+------------------------------------+-----------------------
- // (exp) = explicit
- // (imp) = implicit (happened as result of parent UpdatePanel updating)
- // --------------------------------------------------------------------------
- // in panelsToRefresh = updated
- // not updated, in new = created
- // else = don't care
- // --------------------------------------------------------------------------
-
- var updated = [];
- var created = [];
- var version4 = data ? data.version4 : false;
- var upData = data ? data.updatePanelData : null;
-
- // All panels before update,
- // All panels after update,
- // Child panels created after update,
- // Parent panels created after update
- var newIDs, newClientIDs, childIDs, refreshedIDs;
-
- if (!upData) {
- // this is the initial load, consider the initialized update panels
- // to be the newly created ones
- newIDs = this._updatePanelIDs;
- newClientIDs = this._updatePanelClientIDs;
- childIDs = null;
- refreshedIDs = null;
- }
- else {
- newIDs = upData.updatePanelIDs;
- newClientIDs = upData.updatePanelClientIDs;
- childIDs = upData.childUpdatePanelIDs;
- refreshedIDs = upData.panelsToRefreshIDs;
- }
-
- var i, l, uniqueID, clientID;
- // in panelsToRefresh = updated
- if (refreshedIDs) {
- for (i = 0, l = refreshedIDs.length; i < l; i += (version4 ? 2 : 1)) {
- uniqueID = refreshedIDs[i];
- clientID = (version4 ? refreshedIDs[i+1] : "") || this._uniqueIDToClientID(uniqueID);
- Array.add(updated, document.getElementById(clientID));
- }
- }
-
- // If the panel is in the new list and it is either the initial load
- // of the page a refreshed child, it is 'created'.
- for (i = 0, l = newIDs.length; i < l; i++) {
- if (initialLoad || Array.indexOf(childIDs, newIDs[i]) !== -1) {
- Array.add(created, document.getElementById(newClientIDs[i]));
- }
- }
-
- return new Sys.WebForms.PageLoadedEventArgs(updated, created, data ? data.dataItems : {});
- },
-
- _getPageLoadingEventArgs: function PageRequestManager$_getPageLoadingEventArgs(data) {
- // -------------+------------------------------------+-----------------------
- // Situation | In ID collections | In eventArg property
- // -------------+------------------------------------+-----------------------
- // Update (exp) | in panelsToRefresh | updated
- // Update (imp) | in old, in new, in childUP | deleted
- // Create (exp) | not in old, in new, not in childUP | ---
- // Create (imp) | not in old, in new, in childUP | ---
- // Delete (exp) | in old, not in new, not in childUP | deleted
- // Delete (imp) | in old, not in new, in childUP | deleted
- // -------------+------------------------------------+-----------------------
- // (exp) = explicit
- // (imp) = implicit (happened as result of parent UpdatePanel updating)
- // --------------------------------------------------------------------------
- // in panelsToRefresh = updated
- // not updated, (not in new or in childUP) = deleted
- // else = don't care
- // --------------------------------------------------------------------------
-
- var updated = [],
- deleted = [],
- upData = data.updatePanelData,
- oldIDs = upData.oldUpdatePanelIDs,
- oldClientIDs = upData.oldUpdatePanelClientIDs,
- newIDs = upData.updatePanelIDs,
- childIDs = upData.childUpdatePanelIDs,
- refreshedIDs = upData.panelsToRefreshIDs,
- i, l, uniqueID, clientID,
- version4 = data.version4;
- // in panelsToRefresh = updated
- for (i = 0, l = refreshedIDs.length; i < l; i += (version4 ? 2 : 1)) {
- uniqueID = refreshedIDs[i];
- clientID = (version4 ? refreshedIDs[i+1] : "") || this._uniqueIDToClientID(uniqueID);
- Array.add(updated, document.getElementById(clientID));
- }
-
- // not in new or in childUP = deleted
- for (i = 0, l = oldIDs.length; i < l; i++) {
- uniqueID = oldIDs[i];
- if (Array.indexOf(refreshedIDs, uniqueID) === -1 &&
- (Array.indexOf(newIDs, uniqueID) === -1 || Array.indexOf(childIDs, uniqueID) > -1)) {
- Array.add(deleted, document.getElementById(oldClientIDs[i]));
- }
- }
-
- return new Sys.WebForms.PageLoadingEventArgs(updated, deleted, data.dataItems);
- },
-
- _getPostBackSettings: function PageRequestManager$_getPostBackSettings(element, elementUniqueID) {
-
- var originalElement = element;
-
- // Keep track of whether we have an AsyncPostBackControl but still
- // want to see if we're inside an UpdatePanel anyway.
- var proposedSettings = null;
-
- // Walk up DOM hierarchy to find out the nearest container of
- // the element that caused the postback.
- while (element) {
- if (element.id) {
- // First try an exact match for async postback, regular postback, or UpdatePanel
- if (!proposedSettings && Array.contains(this._asyncPostBackControlClientIDs, element.id)) {
- // The element explicitly causes an async postback
- proposedSettings = this._createPostBackSettings(true, null, elementUniqueID, originalElement);
- }
- else {
- if (!proposedSettings && Array.contains(this._postBackControlClientIDs, element.id)) {
- // The element explicitly doesn't cause an async postback
- return this._createPostBackSettings(false);
- }
- else {
- var indexOfPanel = Array.indexOf(this._updatePanelClientIDs, element.id);
- if (indexOfPanel !== -1) {
- // The element causes an async postback because it is inside an UpdatePanel
- if (this._updatePanelHasChildrenAsTriggers[indexOfPanel]) {
- // If it was in an UpdatePanel and the panel has ChildrenAsTriggers=true, then
- // we do an async postback and refresh the given panel
-
- // Although we do the search by looking at ClientIDs, we end
- // up sending a UniqueID back to the server so that we can
- // call FindControl() with it.
- return this._createPostBackSettings(true, [this._updatePanelIDs[indexOfPanel]], elementUniqueID, originalElement);
- }
- else {
- // The element was inside an UpdatePanel so we do an async postback,
- // but because it has ChildrenAsTriggers=false we don't update this panel.
- return this._createPostBackSettings(true, null, elementUniqueID, originalElement);
- }
- }
- }
- }
-
- // Then try near matches
- if (!proposedSettings && this._matchesParentIDInList(element.id, this._asyncPostBackControlClientIDs)) {
- // The element explicitly causes an async postback
- proposedSettings = this._createPostBackSettings(true, null, elementUniqueID, originalElement);
- }
- else {
- if (!proposedSettings && this._matchesParentIDInList(element.id, this._postBackControlClientIDs)) {
- // The element explicitly doesn't cause an async postback
- return this._createPostBackSettings(false);
- }
- }
- }
-
- element = element.parentNode;
- }
-
- // If we have proposed settings that means we found a match for an
- // AsyncPostBackControl but were still searching for an UpdatePanel.
- // If we got here that means we didn't find the UpdatePanel so we
- // just fall back to the original AsyncPostBackControl settings that
- // we created.
- if (!proposedSettings) {
- // The element doesn't cause an async postback
- return this._createPostBackSettings(false);
- }
- else {
- return proposedSettings;
- }
- },
-
- _getScrollPosition: function PageRequestManager$_getScrollPosition() {
- var d = document.documentElement;
- if (d && (this._validPosition(d.scrollLeft) || this._validPosition(d.scrollTop))) {
- return {
- x: d.scrollLeft,
- y: d.scrollTop
- };
- }
- else {
- d = document.body;
- if (d && (this._validPosition(d.scrollLeft) || this._validPosition(d.scrollTop))) {
- return {
- x: d.scrollLeft,
- y: d.scrollTop
- };
- }
- else {
- if (this._validPosition(window.pageXOffset) || this._validPosition(window.pageYOffset)) {
- return {
- x: window.pageXOffset,
- y: window.pageYOffset
- };
- }
- else {
- return {
- x: 0,
- y: 0
- };
- }
- }
- }
- },
-
- _initializeInternal: function PageRequestManager$_initializeInternal(scriptManagerID, formElement, updatePanelIDs, asyncPostBackControlIDs, postBackControlIDs, asyncPostBackTimeout, masterPageUniqueID) {
- if (this._prmInitialized) {
- throw Error.invalidOperation(Sys.WebForms.Res.PRM_CannotRegisterTwice);
- }
- this._prmInitialized = true;
- this._masterPageUniqueID = masterPageUniqueID;
- this._scriptManagerID = scriptManagerID;
- this._form = Sys.UI.DomElement.resolveElement(formElement);
- this._onsubmit = this._form.onsubmit;
- this._form.onsubmit = null;
- this._onFormSubmitHandler = Function.createDelegate(this, this._onFormSubmit);
- this._onFormElementClickHandler = Function.createDelegate(this, this._onFormElementClick);
- this._onWindowUnloadHandler = Function.createDelegate(this, this._onWindowUnload);
- Sys.UI.DomEvent.addHandler(this._form, 'submit', this._onFormSubmitHandler);
- Sys.UI.DomEvent.addHandler(this._form, 'click', this._onFormElementClickHandler);
- Sys.UI.DomEvent.addHandler(window, 'unload', this._onWindowUnloadHandler);
-
- this._originalDoPostBack = window.__doPostBack;
- if (this._originalDoPostBack) {
- window.__doPostBack = Function.createDelegate(this, this._doPostBack);
- }
- this._originalDoPostBackWithOptions = window.WebForm_DoPostBackWithOptions;
- if (this._originalDoPostBackWithOptions) {
- window.WebForm_DoPostBackWithOptions = Function.createDelegate(this, this._doPostBackWithOptions);
- }
- this._originalFireDefaultButton = window.WebForm_FireDefaultButton;
- if (this._originalFireDefaultButton) {
- window.WebForm_FireDefaultButton = Function.createDelegate(this, this._fireDefaultButton);
- }
- this._originalDoCallback = window.WebForm_DoCallback;
- if (this._originalDoCallback) {
- window.WebForm_DoCallback = Function.createDelegate(this, this._doCallback);
- }
-
- this._pageLoadedHandler = Function.createDelegate(this, this._pageLoadedInitialLoad);
- Sys.UI.DomEvent.addHandler(window, 'load', this._pageLoadedHandler);
- if (updatePanelIDs) {
- this._updateControls(updatePanelIDs, asyncPostBackControlIDs, postBackControlIDs, asyncPostBackTimeout, true);
- }
- },
-
- _matchesParentIDInList: function PageRequestManager$_matchesParentIDInList(clientID, parentIDList) {
- for (var i = 0, l = parentIDList.length; i < l; i++) {
- if (clientID.startsWith(parentIDList[i] + "_")) {
- return true;
- }
- }
- return false;
- },
-
- _onFormElementActive: function PageRequestManager$_onFormElementActive(element, offsetX, offsetY) {
- // element: the form element that is active
- // offsetX/Y: if the element is an image button, the coordinates of the click
- 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) {
- // DevDiv Bugs 146697: tagName needs to be case insensitive to work with xhtml content type
- var tagName = element.tagName.toUpperCase();
- if (tagName === 'INPUT') {
- var type = element.type;
- if (type === 'submit') {
- // DevDiv Bugs 109456: Encode the name as well as the value
- this._additionalInput = encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value);
- }
- else if (type === 'image') {
- // DevDiv Bugs 109456: Encode the name as well as the value
- this._additionalInput = encodeURIComponent(element.name) + '.x=' + offsetX + '&' + encodeURIComponent(element.name) + '.y=' + offsetY;
- }
- }
- else if ((tagName === 'BUTTON') && (element.name.length !== 0) && (element.type === 'submit')) {
- // DevDiv Bugs 109456: Encode the name as well as the value
- this._additionalInput = encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value);
- }
- }
- },
-
- _onFormElementClick: function PageRequestManager$_onFormElementClick(evt) {
- // flag used by fireDefaultButton to know whether calling click() on the default button raised this event.
- this._activeDefaultButtonClicked = (evt.target === this._activeDefaultButton);
- this._onFormElementActive(evt.target, evt.offsetX, evt.offsetY);
- },
-
- _onFormSubmit: function PageRequestManager$_onFormSubmit(evt) {
- var i, l, continueSubmit = true,
- isCrossPost = this._isCrossPost;
- // set to false so subsequent posts that don't go through DPWO aren't considered cross post
- this._isCrossPost = false;
-
- // Call the statically declared form onsubmit statement if there was one
- if (this._onsubmit) {
- continueSubmit = this._onsubmit();
- }
-
- // If necessary, call dynamically added form onsubmit statements
- if (continueSubmit) {
- for (i = 0, l = this._onSubmitStatements.length; i < l; i++) {
- if (!this._onSubmitStatements[i]()) {
- continueSubmit = false;
- break;
- }
- }
- }
-
- if (!continueSubmit) {
- if (evt) {
- evt.preventDefault();
- }
- return;
- }
-
- var form = this._form;
- if (isCrossPost) {
- // Allow the default form submit to take place. Since it's a cross-page postback.
- return;
- }
-
- // DevDiv Bugs 123782
- if (this._activeDefaultButton && !this._activeDefaultButtonClicked) {
- // we are submitting because a default button's click method was called by _fireDefaultButton
- // but calling click() explicitly did not cause a click event or raised it for a different element,
- // so we must manually create the correct postback options.
- // The button was clicked programmatically, so there are no offsetX or offsetY coordinates.
- this._onFormElementActive(this._activeDefaultButton, 0, 0);
- }
-
- // If the postback happened from outside an update panel, fall back
- // and do a normal postback.
- // Dev10 546632: postBackSettings may not exist in certain scenarios where
- // the form click events are cancelled.
- if (!this._postBackSettings || !this._postBackSettings.async) {
- return;
- }
-
- // Construct the form body
- var formBody = new Sys.StringBuilder(),
- count = form.elements.length,
- panelID = this._createPanelID(null, this._postBackSettings);
- // DevDiv Bugs 109456: ScriptManager and UpdatePanel IDs should be encoded as well
- formBody.append(panelID);
-
- for (i = 0; i < count; i++) {
- var element = form.elements[i];
- var name = element.name;
- if (typeof(name) === "undefined" || (name === null) || (name.length === 0) || (name === this._scriptManagerID)) {
- continue;
- }
-
- // DevDiv Bugs 146697: tagName needs to be case insensitive to work with xhtml content type
- var tagName = element.tagName.toUpperCase();
-
- if (tagName === 'INPUT') {
- var type = element.type;
- if ((type === 'text') ||
- (type === 'password') ||
- (type === 'hidden') ||
- (((type === 'checkbox') || (type === 'radio')) && element.checked)) {
- // DevDiv Bugs 109456: Encode the name as well as the value
- formBody.append(encodeURIComponent(name));
- formBody.append('=');
- formBody.append(encodeURIComponent(element.value));
- formBody.append('&');
- }
- }
- else if (tagName === 'SELECT') {
- var optionCount = element.options.length;
- for (var j = 0; j < optionCount; j++) {
- var option = element.options[j];
- if (option.selected) {
- // DevDiv Bugs 109456: Encode the name as well as the value
- formBody.append(encodeURIComponent(name));
- formBody.append('=');
- formBody.append(encodeURIComponent(option.value));
- formBody.append('&');
- }
- }
- }
- else if (tagName === 'TEXTAREA') {
- // DevDiv Bugs 109456: Encode the name as well as the value
- formBody.append(encodeURIComponent(name));
- formBody.append('=');
- formBody.append(encodeURIComponent(element.value));
- formBody.append('&');
- }
- }
-
- // DevDiv Bugs 188713: Some firewalls strip the X-MicrosoftAjax header, so send a custom form field as well.
- formBody.append("__ASYNCPOST=true&");
-
- if (this._additionalInput) {
- formBody.append(this._additionalInput);
- this._additionalInput = null;
- }
-
- var request = new Sys.Net.WebRequest();
- var action = form.action;
- if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
- // DevDiv Bugs 85367: In IE we must encode the path portion of the request because XHR doesn't do it for us.
- // First, we remove the url fragment, which can appear in history-related scenarios
- // but is not relevant to async postbacks.
- var fragmentIndex = action.indexOf('#');
…
Large files files are truncated, but you can click here to view the full file