user6304760
user6304760

Reputation:

asp.net search button just refreshing page

Im trying to create a search button on my website on my homepage which is an aspx page but when I click search all it does is refresh the page instead of preforming the query, any help would be appreciated heres the code for my index.aspx and the code for my index.aspx.cs page

                <asp:TextBox ID="searchtitle" runat="server"></asp:TextBox>
            <asp:Button ID="searchitems" runat="server" Text="Search" />

protected void searchitems_Click(object sender, EventArgs e)
{
    String stext = searchtitle.Text;
    Response.Redirect("search.aspx?searchquery=" + stext);
}

Upvotes: 1

Views: 314

Answers (2)

Usman
Usman

Reputation: 4703

The button is not working because you didnt call the event on the button

<asp:Button ID="searchitems" runat="server" OnClick="searchitems_Click" Text="Search" />

add OnClick attribute with name of the event you want to call and in the given code the event you want to call is searchitems_Click.

Upvotes: 1

Abdus Samad
Abdus Samad

Reputation: 54

definitely when you will click the searchitems page will reload because function for that click is defined on server side.. what you have to do is on the pageload look for the QueryString and get the value of ["searchquery"] then manipulate it as you want.. if you want to not refresh the page use Ajax then...

Upvotes: 0

Related Questions