Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

WebBrowserNavigatingEventArgs Class

Provides data for the WebBrowser.Navigating event.

System.Object
  System.EventArgs
    System.ComponentModel.CancelEventArgs
      System.Windows.Forms.WebBrowserNavigatingEventArgs

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
public class WebBrowserNavigatingEventArgs : CancelEventArgs

The WebBrowserNavigatingEventArgs type exposes the following members.

  NameDescription
Public methodWebBrowserNavigatingEventArgsInitializes a new instance of the WebBrowserNavigatingEventArgs class.
Top
  NameDescription
Public propertyCancelGets or sets a value indicating whether the event should be canceled. (Inherited from CancelEventArgs.)
Public propertyTargetFrameNameGets the name of the Web page frame in which the new document will be loaded.
Public propertyUrlGets the location of the document to which the WebBrowser control is navigating.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The WebBrowser.Navigating event occurs before the WebBrowser control navigates to a new document. You can handle this event to cancel navigation before it begins if certain conditions have not been met, for example, when the user has not completely filled out a form. To do this, set the Cancel property of the WebBrowserNavigatingEventArgs object passed to the event handler to true. You can also use this object to retrieve the location of the new document through the Url property. If the new document will be displayed in a Web page frame, you can retrieve the name of the frame through the TargetFrameName property.

The following code example demonstrates how to use a handler for the WebBrowser.Navigating event to cancel navigation when a Web page form has not been filled in. The WebBrowser.Document property is used to determine whether the form input field contains a value. This example requires that your form contains a WebBrowser control called webBrowser1.


private void Form1_Load(object sender, EventArgs e)
{
    webBrowser1.DocumentText =
        "<html><body>Please enter your name:<br/>" +
        "<input type='text' name='userName'/><br/>" +
        "<a href='http://www.microsoft.com'>continue</a>" +
        "</body></html>";
    webBrowser1.Navigating += 
        new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
}

private void webBrowser1_Navigating(object sender, 
    WebBrowserNavigatingEventArgs e)
{
    System.Windows.Forms.HtmlDocument document =
        this.webBrowser1.Document;

    if (document != null && document.All["userName"] != null && 
        String.IsNullOrEmpty(
        document.All["userName"].GetAttribute("value")))
    {
        e.Cancel = true;
        System.Windows.Forms.MessageBox.Show(
            "You must enter your name before you can navigate to " +
            e.Url.ToString());
    }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.