Tabbed browsing

Hello,

I'm a new developer building a tabbed browser for industrial use. My browser keeps bombing out on the Navigate() method, as follows:

privatevoid Navigate(string address)

{

// Navigates to the given URL if it is valid.

if (String.IsNullOrEmpty(address))return;

if (address.Equals("about:blank"))return;

if (!address.StartsWith("http://") && !address.StartsWith("https://"))

{

address ="http://" + address;

}

try

{

Navigate(address);

}

catch (System.UriFormatException)

{

address ="";

return;

}

}

The error I continue to get is a StackOverflowException; what it means essentially is that when I click on the Go button to call this method, it passes in the string value of the textbox containing the address, but gets stuck in some sort of loop when trying to append the "http://" protocol to the front end of the string. I have even tried turning off the autocomplete function in the address box, to no avail. Suggestions?

[1923 byte] By [pblecha] at [2007-12-24]
# 1
Yep, you're calling your own Navigate method. Try WebBrowser1.Navigate()...
nobugz at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3

I did try that. Here's the thing: I'm dynamically adding the browser after I add a TabPage to each tab. Given that, what would be the correct name for the browser in place of "WebBrowser1" in the code you supply? Would it be something like mainTabs.TabPage.myBrowser?

I guess a follow-up question is, if I add a tab, then add a tabpage, THEN add a browser (all within the preceding object), how do I access the browser if I'm not sending it as an object into the method signature?

Thanks for your help!

pblecha at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
You created the WebBrowser object when you added it to the tab page. You can keep the reference around as a form member, stored in an array or list. Alternatively, you can give the WebBrowser object a name (like "WebBrowser1") before adding it to the tab page. Then you can find the reference back by using TabPage.Controls["WebBrowser1"].

nobugz at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5

That makes sense; I had originally thought to add each webbrowser to an ArrayList (so I can dynamically add and delete them), but the question becomes, would I then access each webbrowser object as the ArrayList member, or as the name stored in the ArrayList? Or, would it make MORE sense to use a simple array of webbrowsers?

Thanks again!

pblecha at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6
You're doing double work if you store the reference in an array, the tabpage has the reference too in its Controls collection. Less code is better...
nobugz at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 7

You're confusing me now. Please re-read my original question.

I agree... less code is better. But how do I reference a dynamically created browser object?

pblecha at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...