Reputation: 19
I'm currently working on a website project and I'm almost done, except that I need to get my searching to work.
I would like it to work like this: On my masterpage there is a asp:textbox
and a asp:button
. When I type in a search word and click on my button I would like it to redirect to a search.aspx page - The problem is, that I don't know how to do that. I only got the method and it looks like this
public DataTable Search(string Keyword)
{
return db.GetData(
"SELECT fldTitle, fldLang, fldCode from tblSnipets LIKE @1",
"%" + Keyword + "%");
}
From there I don't know what to do.
Upvotes: 0
Views: 406
Reputation: 119
Using classic ASP.NET and PostBack event without any patterns it will look like this:
1 - Add an event handler to the button click event.
<asp:Button id="Button1" Text="Search" OnClick="SearchBtn_Click" runat="server"/>
2 - Add SearchBtn_Click handler to the code behind file of your page and do a redirect to your Search page. it will look like this:
void SearchBtn_Click(Object sender, EventArgs e)
{
}
3 - In this event handler write code that will redirect to your Search.aspx with parameters of your search criteria:
Response.Redirect("~/Search.aspx?criteria=" + Server.HtmlEncode(myTextBox.Text));
or close to this statement (check the MSDN)
4 - On the Search.aspx code behinf page in the Page_Load handler catch the parameters and call your method to get the data.
This is not the best solution, but it should work.
Upvotes: 1