Hello Daniwebber's,

I am developing a web browser. When the user clicks "Go" or "Enter" it will navigate to the website, however if it doesn't contain popular website keywords such as "http://" then I know they didn't actually want to go to a website. Then I would have it perform a google search instead, however I need to know ?how to check a textbox value?.

I want to check if when toolStripButton3_Click ("Go" button) is clicked if adrBarTextBox (which is a textbox) contains a value, such as "http", "www", "/", "//", ".", "com", "org", "net". If it doesn't contain that value, I want to perform a google search (which I know how to do).

Sample code:

private void toolStripButton3_Click(object sender, EventArgs e)
// This is the function called when the user clicks "GO" to start going to the website
// I want to check to see if the textbox contains "http", "www", ".", "com", "org", "net", "//", "/"
// The search bar's name is: adrBarTextBox

            if() { // adrBarTextBox.value = "www" does not work. 
                // if it contains "www", we know they actually meant to go to a website:
            getCurrentBrowser().Navigate(adrBarTextBox.Text); // Go to where they asked
            else {
            // Else, we think they meant to search something:
            getCurrentBrowser().Navigate("http://google.com/search?q=" + adrBarTextBox.Text); // Search for keywords on google


All help is appreciated. I have searched MSDN & daniweb references, and came up with nothing about checking inside a textbox for certain values.

6 Years
Discussion Span
Last Post by mshauny

Fixed: Sorry!

Heres the fix:


I didn't know you could also append a condition after ".Text"



I'm not sure of what you are looking for but if you need to check if your TextBox control has values as in test if its null or not. you can just use the string method IsNullOrEmpty which returns a boolean answer. you can use it like :

// has no value
//has value

hope it helps

Edited by mshauny: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.