9 Replies - 21254 Views - Last Post: 19 August 2009 - 11:20 PM Rate Topic: -----

#1 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,280
  • Joined: 25-March 09

Geting URL from WebBrowser

Posted 17 August 2009 - 09:45 AM

hello i try to get the curnet url from webBrowser Control

i try this

Private Function UpdUrtText() As String
		Dim strUrl As String
		strUrl = wbrBrowser.Url.ToString
	End Function



but i get error: "Object reference not set to an instance of an Object"

can you help me with that :)
ty for your time :)

Is This A Good Question/Topic? 0
  • +

Replies To: Geting URL from WebBrowser

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Geting URL from WebBrowser

Posted 17 August 2009 - 09:57 AM

You do have a WebBrowser control named wbrBrowser right?
Was This Post Helpful? 0
  • +
  • -

#3 kewlkreator  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 39
  • View blog
  • Posts: 1,068
  • Joined: 25-March 09

Re: Geting URL from WebBrowser

Posted 17 August 2009 - 10:07 AM

You forgot the () after ToString. That should fix it.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Geting URL from WebBrowser

Posted 17 August 2009 - 10:09 AM

Adding () to the end of ToString() wont get rid of a NullReferenceException.
Was This Post Helpful? 0
  • +
  • -

#5 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,280
  • Joined: 25-March 09

Re: Geting URL from WebBrowser

Posted 17 August 2009 - 10:29 AM

yes my webBrowser is wbrBrowser and yes () dont fix the problem :)
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Geting URL from WebBrowser

Posted 17 August 2009 - 10:51 AM

Your going to need to post more code than that. It appears that the web browser control is out of scope for this function.

Post the rest of the code and I am sure we can help you out.
Was This Post Helpful? 0
  • +
  • -

#7 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,280
  • Joined: 25-March 09

Re: Geting URL from WebBrowser

Posted 17 August 2009 - 11:03 AM

ok :) here is my code

Public Class frmMain

	Private Sub btnGO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGO.Click
		navigateWBRS()
	End Sub


	Private Sub cmbSearch_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cmbSearch.KeyPress
		If e.KeyChar = Chr(Keys.Return) Then


			navigateWBRS()
			UpdUrtText()
		End If
	End Sub

	Private Sub navigateWBRS()
		wbrBrowser.Navigate(cmbSearch.Text)
		If wbrBrowser.CanGoBack Then btnBack.Enabled = True
		If wbrBrowser.CanGoForward Then btnForword.Enabled = True
	End Sub


	Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
		wbrBrowser.Refresh()
	End Sub

	Private Sub btnForword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForword.Click
		wbrBrowser.GoForward()
	End Sub

	Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
		wbrBrowser.GoBack()
	End Sub

	Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		If Not FI.InitPage = "" Then wbrBrowser.Navigate(FI.InitPage)
		btnBack.Enabled = False
		btnForword.Enabled = False
	End Sub


	Private Function UpdUrtText() As String
		Dim strUrl As String
		strUrl = wbrBrowser.Url.ToString()
	End Function
End Class




EDIT: cmbSearch is a combobox
ty for your time dude :)
all i want to do is to update my combobox text property with curent url

This post has been edited by NoBrain: 17 August 2009 - 11:05 AM

Was This Post Helpful? 0
  • +
  • -

#8 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 150
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Geting URL from WebBrowser

Posted 17 August 2009 - 11:06 AM

View PostNoBrain, on 17 Aug, 2009 - 11:03 AM, said:

ok :) here is my code

Public Class frmMain

	Private Sub btnGO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGO.Click
		navigateWBRS()
	End Sub


	Private Sub cmbSearch_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cmbSearch.KeyPress
		If e.KeyChar = Chr(Keys.Return) Then


			navigateWBRS()
			UpdUrtText()
		End If
	End Sub

	Private Sub navigateWBRS()
		wbrBrowser.Navigate(cmbSearch.Text)
		If wbrBrowser.CanGoBack Then btnBack.Enabled = True
		If wbrBrowser.CanGoForward Then btnForword.Enabled = True
	End Sub


	Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
		wbrBrowser.Refresh()
	End Sub

	Private Sub btnForword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForword.Click
		wbrBrowser.GoForward()
	End Sub

	Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
		wbrBrowser.GoBack()
	End Sub

	Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		If Not FI.InitPage = "" Then wbrBrowser.Navigate(FI.InitPage)
		btnBack.Enabled = False
		btnForword.Enabled = False
	End Sub


	Private Function UpdUrtText() As String
		Dim strUrl As String
		strUrl = wbrBrowser.Url.ToString()
	End Function
End Class




EDIT: cmbSearch is a combobox
ty for your time dude :)
all i want to do is to update my combobox text property with curent url

Handle the webbrowser the documentcomplete event and add
cmdbSearch.Text = wbrBrowser.Url.ToString()

Was This Post Helpful? 1
  • +
  • -

#9 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,280
  • Joined: 25-March 09

Re: Geting URL from WebBrowser

Posted 17 August 2009 - 11:11 AM

hey ty that works :) ty
Was This Post Helpful? 0
  • +
  • -

#10 CheckersW  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 198
  • Joined: 04-April 09

Re: Geting URL from WebBrowser

Posted 19 August 2009 - 11:20 PM

Your completed code for this will be:

Private Sub wbrBrowser_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wbrBrowser.DocumentCompleted
		cmbSearch.Text = (wbrBrowser.Url.ToString())
	End Sub



I imagine you want to execute the code upon the DocumentCompleted event (as included in my sample code), but you can change this as you like by changing the selection in the dropbox at the top right of the code tab.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1