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.

Fixed: Sorry!

Heres the fix:

adrBarTextBox.Text.equal("http")

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

Hi

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 :

if(string.IsNullOrEmpty(textbox1.Text))
{
// has no value
}
else
{
//has value
}

hope it helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.