0

I have search button on page. user input som data and click search button. how can search with query string (like google search). is it correct:

void search_click(...)
{
   string item1 = text1.text;
   string item2 = text2.text;
   Responce.Redirect(currentPage.html?x=item1&y=item2);
}

or has better solution.(c#)

Meh Man
  • 463
  • 1
  • 6
  • 22

3 Answers3

0

You need to use GET method on your search form.

Probably the easiest way would be not using ASP.NET controls and using plain HTML components instead:

<form method="get" target="search.aspx">
    Search: <input type="text" name="q" value="Search"><br>
    <input type="submit">
</form>

Then, when the user clicks on Search button, the user will be taken to a place with a URL like:

http://YOUR_SERVER/YOUR_APP/search.aspx?q=hello
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
0

Check out the answer to the same question here: How to build a query string for a URL in C#?

You can build a NameValueCollection and output it as the proper format. The top answer has a great example.

Community
  • 1
  • 1
Jack Lawson
  • 2,479
  • 3
  • 23
  • 24
0

Your code has some errors. Use the following:

Responce.Redirect("currentPage.html?x=" + item1 + "&y=" + item2);
Akram Shahda
  • 14,655
  • 4
  • 45
  • 65