WebBrowserNavigatingEventArgs Class
Provides data for the WebBrowser.Navigating event.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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 Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _ Handles Me.Load 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>" End Sub Private Sub webBrowser1_Navigating( _ ByVal sender As Object, ByVal e As WebBrowserNavigatingEventArgs) _ Handles webBrowser1.Navigating Dim document As System.Windows.Forms.HtmlDocument = _ webBrowser1.Document If document IsNot Nothing And _ document.All("userName") IsNot Nothing And _ String.IsNullOrEmpty( _ document.All("userName").GetAttribute("value")) Then e.Cancel = True MsgBox("You must enter your name before you can navigate to " & _ e.Url.ToString()) End If End Sub
System.EventArgs
System.ComponentModel.CancelEventArgs
System.Windows.Forms.WebBrowserNavigatingEventArgs
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, 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.