HtmlWindow.Error Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when script running inside of the window encounters a run-time error.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public event HtmlElementErrorEventHandler Error
/** @event */
public void add_Error (HtmlElementErrorEventHandler value)

/** @event */
public void remove_Error (HtmlElementErrorEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

HTML pages can contain script code, usually written in JScript or VBScript, that executes when a page is loaded. Error occurs whenever a script encounters a run-time error. Because script code is late-bound, which means that calls against the object are not resolved until run-time, errors can include everything from referencing a null object to calling an undefined property or method.

You can set the Handled property of HtmlElementErrorEventArgs to true in order to prevent the native error dialog box in Internet Explorer from displaying.

For more information about the difference between canceling event bubbling and canceling the default action on an event, see About the DHTML Object Model (http://msdn.microsoft.com/library/default.asp?url=/workshop/author/om/doc_object.asp).

The following code example traps the error that results when a script on an HTML page attempts to access an object that is not defined in the document. The page must be fully loaded before the Error event handler is attached, otherwise the example will not work.

private void SuppressScriptErrors()
{
    if (webBrowser1.Document != null)
    {
        webBrowser1.Document.Window.Error += new HtmlElementErrorEventHandler(scriptWindow_Error);
    }
}

private void  scriptWindow_Error(object sender, HtmlElementErrorEventArgs e)
{
     MessageBox.Show("Suppressed error!");
    e.Handled = true;
}

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

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show: