WebBrowser Control Navigation Issue

WebBrowser Control Navigation

Page 1 of 1

6 Replies - 10989 Views - Last Post: 28 July 2008 - 09:04 AM Rate Topic: -----

#1 BryanGilbert  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-July 08

WebBrowser Control Navigation Issue

Post icon  Posted 25 July 2008 - 09:53 PM

Hi ,
I am developing one win application IN C# which makes use of WebBrowser control.
I am passing the url in a text box and the page is getting displayed in the web browser control.Till this its fine.Whn ever a link is clicked inside the webbrowser control it is opening in the same page.

Is there any way such that the clicked links inside a webbrowser control should open in a new tab with the tab having the page title.Imean dynamically open in a new webbrowser control...

I in fact tried this code in the navigating event of webbrowser control.But it is also opening a new tab and inthe browser which is newly created is having the message "action cancelled".
The clicked url is getting opened in the 1st browser control...


Here is the piece of code i tried ...

Please help ...


void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
		{
 
			navigatedUrl = webBrowser1.StatusText.ToString();
			int tab_count = 0;
			string tabName;
			tab_count = tabControl1.Controls.Count;
			tabName = "TabPage" + ++tab_count;
			TabPage tabNew = new TabPage();
 
			tabNew.Location = new System.Drawing.Point(4, 24);
			tabNew.Padding = new System.Windows.Forms.Padding(3);
			tabNew.Size = new System.Drawing.Size(800, 517);
			tabNew.TabIndex = 0;
			tabNew.Text = tabName;
			tabNew.UseVisualStyleBackColor = true;
			tabControl1.Controls.Add(tabNew);
			tabNew.Name = tabName;
			string webName = "webBrowser" + tab_count;
 
			WebBrowser webNew = new WebBrowser();
			webNew.Dock = System.Windows.Forms.DockStyle.Fill;
			webNew.Location = new System.Drawing.Point(3, 3);
			webNew.MinimumSize = new System.Drawing.Size(20, 20);
			webNew.Name = webName;
			webNew.Size = new System.Drawing.Size(794, 511);
			webNew.TabIndex = 0;
			webNew.AllowNavigation = true;
			tabNew.Controls.Add(webNew);
			 webNew.Navigate(navigatedUrl );
		}




--------------------------------------------------------------------------------


Thanks in advance ,

Bryan

Is This A Good Question/Topic? 0
  • +

Replies To: WebBrowser Control Navigation Issue

#2 mijatra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-July 08

Re: WebBrowser Control Navigation Issue

Posted 27 July 2008 - 10:27 AM

string navigatedUrl = webBrowser1.Url.ToString();

Try this instead!
Was This Post Helpful? 0
  • +
  • -

#3 BryanGilbert  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-July 08

Re: WebBrowser Control Navigation Issue

Posted 27 July 2008 - 11:28 PM

View Postmijatra, on 27 Jul, 2008 - 10:27 AM, said:

string navigatedUrl = webBrowser1.Url.ToString();

Try this instead!

Hi mijatra,

Thanks for the reply ... I put string navigatedUrl = webBrowser1.Url.ToString(); in the navigating event.

Now whts happening is The clicked link is opening in the 1st tab and the intial (loaded page) page is loaded in a new tab ...
Is there any way to reverse this i.e the initial browser page shud be in the 1st tab and the clicked link should open in an new tab ...


Thanks for your valuable sugessions,
Bryan
Was This Post Helpful? 0
  • +
  • -

#4 mijatra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-July 08

Re: WebBrowser Control Navigation Issue

Posted 28 July 2008 - 01:59 AM

Sorry, my bad.

This should solve the problem:

string navigatedUrl = e.Url.ToString();
e.Cancel = true;
Was This Post Helpful? 0
  • +
  • -

#5 BryanGilbert  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-July 08

Re: WebBrowser Control Navigation Issue

Posted 28 July 2008 - 02:18 AM

View Postmijatra, on 28 Jul, 2008 - 01:59 AM, said:

Sorry, my bad.

This should solve the problem:

string navigatedUrl = e.Url.ToString();
e.Cancel = true;

Hi mijatra,
Thanks for you valuable time ....HARD LUCK !!!!! It's not working as still the intial page loads in a new tab and the clicked link opens in the first tab ....
I need to put this code in the Navigating event right of the static browser i.e.
void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)


AM I RIGHT ?????

thanks once again,
Bryan
Was This Post Helpful? 0
  • +
  • -

#6 mijatra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-July 08

Re: WebBrowser Control Navigation Issue

Posted 28 July 2008 - 05:46 AM

Yeah, I mean I've made some kind of a simple app, and it worked fine.

It opened clicked url in new tab, and stoped the navigation of static webbrowser control.
Was This Post Helpful? 0
  • +
  • -

#7 mijatra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-July 08

Re: WebBrowser Control Navigation Issue

Posted 28 July 2008 - 09:04 AM

View PostBryanGilbert, on 25 Jul, 2008 - 09:53 PM, said:

Hi ,
I am developing one win application IN C# which makes use of WebBrowser control.
I am passing the url in a text box and the page is getting displayed in the web browser control.Till this its fine.Whn ever a link is clicked inside the webbrowser control it is opening in the same page.

Is there any way such that the clicked links inside a webbrowser control should open in a new tab with the tab having the page title.Imean dynamically open in a new webbrowser control...

I in fact tried this code in the navigating event of webbrowser control.But it is also opening a new tab and inthe browser which is newly created is having the message "action cancelled".
The clicked url is getting opened in the 1st browser control...


Here is the piece of code i tried ...

Please help ...


void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
		{
						//added code
			navigatedUrl = e.Url.ToString();
						e.Cancel = true;
						//
			int tab_count = 0;
			string tabName;
			tab_count = tabControl1.Controls.Count;
			tabName = "TabPage" + ++tab_count;
			TabPage tabNew = new TabPage();
 
			tabNew.Location = new System.Drawing.Point(4, 24);
			tabNew.Padding = new System.Windows.Forms.Padding(3);
			tabNew.Size = new System.Drawing.Size(800, 517);
			tabNew.TabIndex = 0;
			tabNew.Text = tabName;
			tabNew.UseVisualStyleBackColor = true;
			tabControl1.Controls.Add(tabNew);
			tabNew.Name = tabName;
			string webName = "webBrowser" + tab_count;
 
			WebBrowser webNew = new WebBrowser();
			webNew.Dock = System.Windows.Forms.DockStyle.Fill;
			webNew.Location = new System.Drawing.Point(3, 3);
			webNew.MinimumSize = new System.Drawing.Size(20, 20);
			webNew.Name = webName;
			webNew.Size = new System.Drawing.Size(794, 511);
			webNew.TabIndex = 0;
			webNew.AllowNavigation = true;
			tabNew.Controls.Add(webNew);
			 webNew.Navigate(navigatedUrl );
		}




--------------------------------------------------------------------------------


Thanks in advance ,

Bryan

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1