Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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 <iframe> 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 <iframe> 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)

↑ Back to the top


Cause

This problem occurs because the Web page that contains the <iframe> element and the Web page to which the <iframe> 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.

↑ Back to the top


Resolution

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

Method 1

Make sure that the Web page that contains the <iframe> element and the Web page to which the <iframe> 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

  1. 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.
  2. On the Web page that contains the <iframe> element, specify a value for the ScriptPath attribute in the <ScriptManager> element. The following code looks for the scripts in a folder that is named Scripts in the application root directory.
    <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptPath="~/Scripts" />
  3. Copy the System.Web.Extensions folder in the AJAX Library into the Scripts folder.
  4. 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.
    <script src="Scripts/System.Web.Extensions/1.0.61025.0/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="Scripts/System.Web.Extensions/1.0.61025.0/MicrosoftAjaxWebForms.js" type="text/javascript"></script>
    

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 <compilation> 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:
  1. Open the MicrosoftAjax.debug.js file. This file is located in the following folder:
    Application Root Directory/Scripts/System.Web.Extensions/1.0.61025.0
  2. 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:
    
  3. 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;
    
  4. Save the MicrosoftAjax.debug.js file.
  5. Open the Web.config file in the ASP.NET program, and then set the debug attribute to True in the <compilation> element.
  6. Save the Web page.

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:
  1. Open the MicrosoftAjax.js file in the Scripts folder.
  2. 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:
  3. 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;
  4. Save the MicrosoftAjax.js file.
  5. Open the Web.config file in the ASP.NET program, and then set the debug attribute to True in the <compilation> element.
  6. Save the Web page.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

For more information about the <iframe> element, visit the following Microsoft Developer Network (MSDN) Web site:

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: KB936993, kbprb, kbtshoot, kbasp, kbfix, kbwebbrowser, kberrmsg

↑ Back to the top

Article Info
Article ID : 936993
Revision : 2
Created on : 9/3/2012
Published on : 9/3/2012
Exists online : False
Views : 520