Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm using thw WebBrowser control on one of my forms. What I'd like to do is have the it do a we search based on the contents of a textbox control.

 

Anyone know how?

 

Thanks,

Bernie

Posted

If you have a look at the url of a site like Google after a search you can see what variables are used to POST to their engine.

 

Eg. Typing "word1 word2 word3" into Google results in:

 

http://www.google.com.au/search?q=word1+word2+word3

 

If you take this as a reference you can take your TextBox text and create a url for it.

 

Eg. string myURL = "http://www.google.com.au/search?q=" + String.Join('+', myTextBox.Text.Split(' '));

 

Then send myURL to your browser control and it should show google with the words from your TextBox.

Posted

Thanks for the reply but I'm getting the blue squigle line under the First ( of String.Join('+', myTextBox.Text.Split(' ')); Says, expression expected.

 

 

If you have a look at the url of a site like Google after a search you can see what variables are used to POST to their engine.

 

Eg. Typing "word1 word2 word3" into Google results in:

 

http://www.google.com.au/search?q=word1+word2+word3

 

If you take this as a reference you can take your TextBox text and create a url for it.

 

Eg. string myURL = "http://www.google.com.au/search?q=" + String.Join('+', myTextBox.Text.Split(' '));

 

Then send myURL to your browser control and it should show google with the words from your TextBox.

Posted

Got it. WebBrowser1.Navigate("http://www.google.com.au/search?q=" + txtWebSearch.Text)

 

Thanks for helping.

 

If you have a look at the url of a site like Google after a search you can see what variables are used to POST to their engine.

 

Eg. Typing "word1 word2 word3" into Google results in:

 

http://www.google.com.au/search?q=word1+word2+word3

 

If you take this as a reference you can take your TextBox text and create a url for it.

 

Eg. string myURL = "http://www.google.com.au/search?q=" + String.Join('+', myTextBox.Text.Split(' '));

 

Then send myURL to your browser control and it should show google with the words from your TextBox.

Posted

All that hoohaa was just to split up the text in the TextBox into an array of words separated by a space, then bring them back together placing a "+" between them.

 

myTextBox.Text = "word1 word2 word3";

MessageBox.Show(String.Join("+", myTextBox.Text.Split(' ')));

 

Will ouput "word1+word2+word3". The error you got was because I accidently used single quotes for a char in the Join method when it expects double quotes for a string.

Posted

Thanks again. I've found that with the code I included (in my last email), that it will still work on multiple words as your's does.

 

All that hoohaa was just to split up the text in the TextBox into an array of words separated by a space, then bring them back together placing a "+" between them.

 

myTextBox.Text = "word1 word2 word3";

MessageBox.Show(String.Join("+", myTextBox.Text.Split(' ')));

 

Will ouput "word1+word2+word3". The error you got was because I accidently used single quotes for a char in the Join method when it expects double quotes for a string.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...