Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
WebBrowser Class
 ScriptErrorsSuppressed Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
WebBrowser..::.ScriptErrorsSuppressed Property

Updated: November 2007

Gets or sets a value indicating whether the WebBrowser displays dialog boxes such as script error messages.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

Visual Basic (Declaration)
Public Property ScriptErrorsSuppressed As Boolean
Visual Basic (Usage)
Dim instance As WebBrowser
Dim value As Boolean

value = instance.ScriptErrorsSuppressed

instance.ScriptErrorsSuppressed = value
C#
public bool ScriptErrorsSuppressed { get; set; }
Visual C++
public:
property bool ScriptErrorsSuppressed {
    bool get ();
    void set (bool value);
}
J#
/** @property */
public boolean get_ScriptErrorsSuppressed()
/** @property */
public  void set_ScriptErrorsSuppressed(boolean value)
JScript
public function get ScriptErrorsSuppressed () : boolean
public function set ScriptErrorsSuppressed (value : boolean)

Property Value

Type: System..::.Boolean

true if the control does not display its dialog boxes; otherwise, false. The default is false.

ExceptionCondition
ObjectDisposedException

This WebBrowser instance is no longer valid.

InvalidOperationException

A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

Set this property to false to debug Web pages that you display in the WebBrowser control. This is useful when you use the control to add Web-based controls and scripting code to your application. It is less useful when you use the control as a generic browser. When you have finished debugging your application, set this property to true to suppress script errors.

Note:

When ScriptErrorsSuppressed is set to true, the WebBrowser control hides all its dialog boxes that originate from the underlying ActiveX control, not just script errors. Occasionally you might need to suppress script errors while displaying dialog boxes such as those used for browser security settings and user login. In this case, set ScriptErrorsSuppressed to false and suppress script errors in a handler for the HtmlWindow..::.Error event. For more information, see the code example in this topic.

The following code example demonstrates how to suppress script errors without suppressing other dialog boxes. In the example, the ScriptErrorsSuppressed property is set to false to ensure that dialog boxes are displayed. A handler for the HtmlWindow..::.Error event suppresses the error. This event is only accessible when a document is finished loading, so the handler is attached in a DocumentCompleted event handler.

Visual Basic
' Hides script errors without hiding other dialog boxes.
Private Sub SuppressScriptErrorsOnly(ByVal browser As WebBrowser)

    ' Ensure that ScriptErrorsSuppressed is set to false.
    browser.ScriptErrorsSuppressed = False

    ' Handle DocumentCompleted to gain access to the Document object.
    AddHandler browser.DocumentCompleted, _
        AddressOf browser_DocumentCompleted

End Sub

Private Sub browser_DocumentCompleted(ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs)

    AddHandler CType(sender, WebBrowser).Document.Window.Error, _
        AddressOf Window_Error

End Sub

Private Sub Window_Error(ByVal sender As Object, _
    ByVal e As HtmlElementErrorEventArgs)

    ' Ignore the error and suppress the error dialog box. 
    e.Handled = True

End Sub

C#
// Hides script errors without hiding other dialog boxes.
private void SuppressScriptErrorsOnly(WebBrowser browser)
{
    // Ensure that ScriptErrorsSuppressed is set to false.
    browser.ScriptErrorsSuppressed = false;

    // Handle DocumentCompleted to gain access to the Document object.
    browser.DocumentCompleted +=
        new WebBrowserDocumentCompletedEventHandler(
            browser_DocumentCompleted);
}

private void browser_DocumentCompleted(object sender, 
    WebBrowserDocumentCompletedEventArgs e)
{
    ((WebBrowser)sender).Document.Window.Error += 
        new HtmlElementErrorEventHandler(Window_Error);
}

private void Window_Error(object sender, 
    HtmlElementErrorEventArgs e)
{
    // Ignore the error and suppress the error dialog box. 
    e.Handled = true;
}

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker