简体   繁体   中英

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 .

As per discussion in comment, issue is here:

CodeBehind="Main.aspx.cs

Change it to

CodeFile="Main.aspx.cs"

This will solved your error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM