0

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.

1
  • You can have the button submit a post request to the search.aspx page, then call the search method there. Commented Aug 17, 2012 at 18:50

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Make sure you sanitize all inputs being sent into SQL (parameterize them at least).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.