user5468794 user5468794 - 2 months ago 8
HTML Question

Onclick event not working/redirecting

This is the first webservice I have made and I am having issues with my current functionality. My button in Visual Studio will only accept

OnClientClick
without the error below. My button is defined as such in my .aspx:

<asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search">


The aspx.cs file contains this:

protected void btnSearch_Click(object sender, EventArgs e)
{
Response.Redirect("www.google.com"); //just for a testing
}


The error thrown is:


CS1061: 'ASP.main_aspx' does not contain a definition for
'btnSearch_Click' and no extension method 'btnSearch_Click' accepting a
first argument of type 'ASP.main_aspx' could be found


I have looked at various posts about
onclick
events and nothing I have tried has been the solution. Any ides on why when I click my button it doesn't redirect? Also I would like to use
OnClick
rather than
OnClient
.

Div Div
Answer

As per discussion in comment, issue is here:

CodeBehind="Main.aspx.cs

Change it to

CodeFile="Main.aspx.cs"

This will solved your error.