subha
subha

Reputation: 677

Does not contain definition error for Button click event in asp.net page

i have a button in edit.aspx page with below code

<asp:Button ID="GoButton" runat="server" Text="Go" onclick="GoButton_Click" />

then the page directive is as follows

<%@ Page language="c#"  EnableEventValidation="false" Codebehind="AdminHotelEdit.aspx.cs" AutoEventWireup="false" Inherits="GTIAdmin.AdminHotelEdit" ValidateRequest="false"%>

and i have the button click event defined in code behind file as follows

public void GoButton_Click(object sender, EventArgs e)
{
}

when i debug program is getting error stating that

Error   146 'ASP.edit_aspx' does not contain a definition for 'GoButton_Click'
and no extension method 'GoButton_Click' accepting a first argument of type
'ASP.adminhoteledit_aspx' could be found (are you missing a using directive or an
assembly reference?)    

please suggest me if you have idea about the reason of this error.

the code in edit.cs is as follows

namespace GTIAdmin
{
    /// <summary>
    /// Summary description for AdminHotelEdit.
    /// </summary>

    public class AdminHotelEdit : GTIAdminPage
    {
        protected Button GoButton_Click;

        private void Page_Load(object sender, System.EventArgs e)
        {

        }

        public void GoButton_Click(object sender, EventArgs e)
        {

        }
    }
}

Upvotes: 5

Views: 39800

Answers (3)

user3661035
user3661035

Reputation: 1

public void GoButton_Click(object sender, EventArgs e)

try this..

protected void GoButton_Click(object sender, EventArgs e)

Upvotes: -1

dahlbyk
dahlbyk

Reputation: 77540

Change this...

    protected Button GoButton_Click;

...to this...

    protected Button GoButton;

...to match the ID of the button in your ASPX and eliminate a name conflict with your event handler method.

Upvotes: 0

Noon Silk
Noon Silk

Reputation: 55082

Show us the contents of 'Edit.aspx.cs'

-- edit:

The 'inherits' field is blank. Set it to the name of the class in 'Edit.aspx.cs' and life should be good.

-- edit again:

Nope. It's because AutoEventWireup is false.

Upvotes: 3

Related Questions