AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005
AddHandler in VB.NET 2005 AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
Go Back  Xtreme Visual Basic Talk > > > AddHandler in VB.NET 2005


Reply
 
Thread Tools Display Modes
  #1  
Old 05-26-2006, 07:47 AM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default AddHandler in VB.NET 2005


I have the following Handler:

Private Sub wbTabExplorer_NavigateComplete2(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs)

End Sub


Added to a WebBrowser at runtime using:

AddHandler wbTabExplorer.Navigating, AddressOf wbTabExplorer_NavigateComplete2

All webbrowsers are added at runtime.

How do I get the .LocationName for the browser that initiated the Handler?

Thanks
Reply With Quote
  #2  
Old 05-26-2006, 09:25 AM
shaul_ahuvaAddHandler in VB.NET 2005 shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

The sender parameter is the object that raised the event, so just cast to WebBrowser
Reply With Quote
  #3  
Old 05-26-2006, 11:51 AM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

Do you have an example? I tried the following:

Code:
    Private Sub wbTabExplorer_NavigateComplete2(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs)
        Me.Text = wbTabExplorer.LocationName
    End Sub
But it does not recognise wbTabExplorer


EDIT: I changed the word 'wbTabExplorer' to sender and it recognised the line, however, did not seem to work!

Last edited by tonymaclennan; 05-26-2006 at 12:04 PM.
Reply With Quote
  #4  
Old 05-26-2006, 12:19 PM
wayneph's Avatar
waynephAddHandler in VB.NET 2005 wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Me.Text = DirectCast(sender, WebBrowser).LocationName
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #5  
Old 05-26-2006, 01:11 PM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

It says for WebBrowser:

"locationname is not a member of system.windows.forms.webbrowser

i substituted WebBrowser for wbTabExplorer and it then said:

Type wbTabExplorer is not defined
Reply With Quote
  #6  
Old 05-26-2006, 01:14 PM
wayneph's Avatar
waynephAddHandler in VB.NET 2005 wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

What type of object is wbTabExplorer? Replace WebBrowser in the DirectCast sample with the correct type for you object.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #7  
Old 05-26-2006, 01:20 PM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

The object is WebBrowser!
Reply With Quote
  #8  
Old 05-26-2006, 01:39 PM
shaul_ahuvaAddHandler in VB.NET 2005 shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

It sounds like you're using the ActiveX web browser (SHDocVw.AxWebBrowser), so the class name would be AxWebBrowser.

I would suggest switching to the .NET 2.0 managed wrapper (System.Windows.Forms.WebBrowser). If you continue to use the AxWebBrowser directly, the type name in the cast should be AxWebBrowser.
Reply With Quote
  #9  
Old 05-26-2006, 01:54 PM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

when i put AxWebBrowser it says;

AxWebBrowser is not defined

Im using 2005 Express version, upgraded from .net 2003
Reply With Quote
  #10  
Old 05-26-2006, 01:58 PM
jwakeman's Avatar
jwakeman jwakeman is offline
Contributor
 
Join Date: Jul 2005
Posts: 420
Default

Quote:
Originally Posted by tonymaclennan
It says for WebBrowser:

"locationname is not a member of system.windows.forms.webbrowser

i substituted WebBrowser for wbTabExplorer and it then said:

Type wbTabExplorer is not defined

That is because locationname IS NOT a member of windows.forms.webbrowser, as the error says. Maybe you want to use something like documenttitle or another property of the webbrowser control.

if you use intellisense to view the members of your declared webbrowser you will not see locationname. For example:

Code:
Dim browser as webbrowser
browser.
locationname does not show up in the list!
Reply With Quote
  #11  
Old 05-26-2006, 02:52 PM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

ah ye, sorry, was using coding from 2003!
Reply With Quote
  #12  
Old 05-26-2006, 03:23 PM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

This is the wierd thing though, the AddHandle/Handler is not working as should be!

Code:
Private Sub wbTabExplorer_NavigationComplete2(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Me.Text = DirectCast(sender, WebBrowser).DocumentTitle End Sub

It does not actually change the page title!

I then asked for it to display a messagebox to ensure if was not working, and on NavigationComplete, the text box did not appear!

What have I done wrong?
Reply With Quote
  #13  
Old 05-26-2006, 03:38 PM
wayneph's Avatar
waynephAddHandler in VB.NET 2005 wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

where do you call AddHandler? maybe you could show us that part...
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #14  
Old 05-27-2006, 01:53 AM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

I add the handler to the WebBrowser object when a buton is clicked (at the same time the WebBrowser Object is created).

I use the following code:

AddHandler wbTabExplorer.Navigating, AddressOf wbTabExplorer_NavigationComplete2

Then I have created the Handler which contains the code!

Was there something else I should have done?
Reply With Quote
  #15  
Old 05-27-2006, 03:14 AM
shaul_ahuvaAddHandler in VB.NET 2005 shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Post

The Navigating event occurs before the navigation actually happens, so there's no document to get a title from.

Check out the WebBrowser class reference to see if another event (such as DocumentTitleChanged) would be of more use.
Reply With Quote
  #16  
Old 05-27-2006, 03:02 PM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

Using the _NewWindow option, how would I go about gettign the URL of the webpage about to be navigated to??
Reply With Quote
  #17  
Old 05-28-2006, 10:23 PM
jwakeman's Avatar
jwakeman jwakeman is offline
Contributor
 
Join Date: Jul 2005
Posts: 420
Default

Quote:
Originally Posted by tonymaclennan
Using the _NewWindow option, how would I go about gettign the URL of the webpage about to be navigated to??
I know you are looking for some property you can reference but didn't you tell the browser which URL to navigate to? You should be able to keep track of that somehow and use it wherever you need it.
Reply With Quote
  #18  
Old 05-29-2006, 03:00 AM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

Quote:
Originally Posted by jwakeman
I know you are looking for some property you can reference but didn't you tell the browser which URL to navigate to? You should be able to keep track of that somehow and use it wherever you need it.
I tell the WebBrowser the initial page it should go to, but the user can then navigate within that website (or follow an external website link). But I have no method of catching the New URL that they are opening in the new window!
Reply With Quote
  #19  
Old 05-29-2006, 06:13 AM
jwakeman's Avatar
jwakeman jwakeman is offline
Contributor
 
Join Date: Jul 2005
Posts: 420
Default

Code:
 Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
        Dim wb As WebBrowser = DirectCast(sender, WebBrowser)
        MsgBox(wb.Url)
    End Sub
Reply With Quote
  #20  
Old 05-29-2006, 01:27 PM
tonymaclennan tonymaclennan is offline
Contributor
 
Join Date: Sep 2004
Location: Lincolnshire
Posts: 402
Default

That just gives the URL of the current page!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005 AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005 AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
 
AddHandler in VB.NET 2005
AddHandler in VB.NET 2005
 
-->