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]
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!
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!
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?