开发者

search button in page and pass item as query string

I have search button on page. user input som data and click search button. how can search with query string (like go开发者_Python百科ogle 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#)


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


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.


Your code has some errors. Use the following:

Responce.Redirect("currentPage.html?x=" + item1 + "&y=" + item2);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜