Microsoft KB Archive/936993

= Error message when you access a Web page that runs an AJAX 1.0-enabled ASP.NET 2.0 program: &quot;A Runtime Error has occurred&quot; =

Article ID: 936993

Article Last Modified on 6/1/2007

-

APPLIES TO


 * Microsoft ASP.NET 2.0

-



SYMPTOMS
You receive the following error message when you access a Web page that runs an AJAX 1.0-enabled Microsoft ASP.NET 2.0 program:

A Runtime Error has occurred.

Do you wish to Debug?

Line: 5

Error: Access is Denied

This error message occurs if the following conditions are true:
 * You use an element in a Web page that points to another Web page from a different domain.
 * The Web page from a different domain uses ASP.NET AJAX server controls.
 * You perform an action in the element that triggers an asynchronous postback operation.
 * In Microsoft Internet Explorer, you click to select the following check boxes under Browsing on the Advanced tab in Internet Options:
 * Disable script debugging (Internet Explorer)
 * Disable script debugging (Other)



CAUSE
This problem occurs because the Web page that contains the element and the Web page to which the element points are in different domains. The AJAX 1.0-enabled ASP.NET script fails when it tries to determine the offset of the content.



RESOLUTION
To resolve this problem, use one of the following methods.

Method 1
Make sure that the Web page that contains the element and the Web page to which the element points are in the same domain.

Method 2
Update the JavaScript files to avoid the error message. Use the external script files that exist in the AJAX Library package instead of the resource-based files that exist in the AJAX Extension package. To do this, follow these steps.

Step 1: Configure the Web page to use the script files instead of the resource-based files
 Download and then extract the AJAX Library from the Microsoft Download Center.

The following file is available for download from the Microsoft Download Center:

Download the Microsoft AJAX Library package now.

For more information about how to download Microsoft support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to obtain Microsoft support files from online services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help prevent any unauthorized changes to the file.  On the Web page that contains the element, specify a value for the ScriptPath attribute in the  element. The following code looks for the scripts in a folder that is named Scripts in the application root directory.   Copy the System.Web.Extensions folder in the AJAX Library into the Scripts folder.  Access the ASPX page to confirm that the script files are called from the Scripts folder. To do this, click Source on the View menu in Internet Explorer. Locate the following two script tags.   </ol>

Step 2: Modify the MicrosoftAjax.debug.js file to avoid the error message
You must use the MicrosoftAjax.debug.js file when the debug attribute in the element is set to True in the Web.config file. The MicrosoftAjax.debug.js file contains line breaks. To modify the MicrosoftAjax.debug.js file, follow these steps: <ol style="list-style-type: lower-alpha;"> Open the MicrosoftAjax.debug.js file. This file is located in the following folder:

/Scripts/System.Web.Extensions/1.0.61025.0

</li>  Locate the following two lines of code. (There may be code between these two lines.) switch(Sys.Browser.agent) { case Sys.Browser.InternetExplorer:

case Sys.Browser.Safari: </li>  Paste the following code between the two lines of code that are listed in step 2b. If code exists between the two lines, replace the code.

New Code Sys.UI.DomElement.getLocation = function(element) { if (element.self || element.nodeType === 9) return new Sys.UI.Point(0,0);

var clientRect = element.getBoundingClientRect; if (!clientRect) { return new Sys.UI.Point(0,0); }

var ownerDocument = element.document.documentElement;

var offsetX = clientRect.left - 2 + ownerDocument.scrollLeft, offsetY = clientRect.top - 2 + ownerDocument.scrollTop; try { var f = element.ownerDocument.parentWindow.frameElement || null; if (f) { var offset = 2 - (f.frameBorder || 1) * 2; offsetX += offset; offsetY += offset; }           }            catch(ex) { }               return new Sys.UI.Point(offsetX, offsetY); }       break; </li> Save the MicrosoftAjax.debug.js file.</li> Open the Web.config file in the ASP.NET program, and then set the debug attribute to True in the element.</li> Save the Web page.</li></ol>

Step 3: Modify the MicrosoftAjax.js file to avoid the error message
The MicrosoftAjax.js file is the release version of the MicrosoftAjax.debug.js file. The MicrosoftAjax.js does not contain line breaks. To modify the MicrosoftAjax.js file, follow these steps: <ol style="list-style-type: lower-alpha;"> Open the MicrosoftAjax.js file in the Scripts folder.</li>  Locate the following two lines of code. (There may be code between these two lines.) switch(Sys.Browser.agent){case Sys.Browser.InternetExplorer:

case Sys.Browser.Safari: </li>  Paste the following code between the two lines of code that are listed in step 3b. If code exists between the two lines, replace the code.

New Code Sys.UI.DomElement.getLocation=function(a){if(a.self||a.nodeType===9) return new Sys.UI.Point(0,0); var b=a.getBoundingClientRect; if(!b) return new Sys.UI.Point(0,0); var c=a.document.documentElement,d=b.left-2+c.scrollLeft,e=b.top-2+c.scrollTop; try{var g=a.ownerDocument.parentWindow.frameElement||null; if(g){var f=2-(g.frameBorder||1)*2; d+=f;e+=f}}catch(h){}return new Sys.UI.Point(d,e)}; break; </li> Save the MicrosoftAjax.js file.</li> Open the Web.config file in the ASP.NET program, and then set the debug attribute to True in the element.</li> Save the Web page.</li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
For more information about the element, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/ms535258.aspx

For more information about ASP.NET AJAX, visit the following Microsoft Web site:

http://ajax.asp.net/about/default.aspx?tabid=47

Keywords: kberrmsg kbwebbrowser kbfix kbasp kbtshoot kbprb KB936993

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.