WebBrowser.Navigating Event
Assembly: System.Windows.Forms (in system.windows.forms.dll)
'Declaration Public Event Navigating As WebBrowserNavigatingEventHandler 'Usage Dim instance As WebBrowser Dim handler As WebBrowserNavigatingEventHandler AddHandler instance.Navigating, handler
/** @event */ public void add_Navigating (WebBrowserNavigatingEventHandler value) /** @event */ public void remove_Navigating (WebBrowserNavigatingEventHandler value)
JScript supports the use of events, but not the declaration of new ones.
The WebBrowser control navigates to a new document whenever one of the following properties is set or methods is called:
You can handle the Navigating event to cancel navigation if certain conditions have not been met, for example, when the user has not completely filled out a form. To cancel navigation, set the Cancel property of the WebBrowserNavigatingEventArgs object passed to the event handler to true. You can also use this object to retrieve the URL of the new document through the WebBrowserNavigatingEventArgs.Url property. If the new document will be displayed in a Web page frame, you can retrieve the name of the frame through the WebBrowserNavigatingEventArgs.TargetFrameName property.
Handle the Navigated event to receive notification when the WebBrowser control finishes navigation and has begun loading the document at the new location. Handle the DocumentCompleted event to receive notification when the WebBrowser control finishes loading the new document.
For more information about handling events, see Consuming Events.
The following code example demonstrates how to use a handler for the Navigating event to cancel navigation when a Web page form has not been filled in. The 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 and that your form class has a ComVisibleAttribute making it accessible to COM.
For a complete code example that you can paste the following code into, see How to: Add Web Browser Capabilities to a Windows Forms Application.
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
- SecurityPermission for immediate callers to use this control. Demand value: LinkDemand; Named Permission Sets: FullTrust.
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.
Reference
WebBrowser ClassWebBrowser Members
System.Windows.Forms Namespace
WebBrowser.DocumentCompleted Event
WebBrowser.DocumentStream Property
WebBrowser.DocumentText Property
GoBack
GoForward
GoHome
GoSearch
Navigate
WebBrowser.Navigated Event
WebBrowser.Url Property
WebBrowserNavigatingEventArgs
WebBrowserNavigatingEventHandler