Button1_Click is not a member of ASP default2_aspx

Button1_Click is not a member of ASP default2_aspx

The error message “Button1_Click is not a member of ASP.default2_aspx” typically occurs when there is a mismatch between the code-behind file and the ASPX file in an ASP.NET application.

Here’s an example:

public partial class Default2 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        // Do something

    }

}

In this example, we have a Default2.aspx.cs file that contains a Button1_Click event handler method. However, if the corresponding ASPX file (Default2.aspx) does not have a reference to this event handler method, we can get the “Button1_Click is not a member of ASP.default2_aspx” error.

To fix this, you need to ensure that the ASPX file has the correct CodeBehind or CodeFile attribute that references the correct code-behind file. Here’s an example:

<%@ Page Language=”C#” CodeBehind=”Default2.aspx.cs” Inherits=”MyProject.Default2″ %>

<!DOCTYPE html>

<html>

<head>

    <title>Default2</title>

</head>

<body>

    <form runat=”server”>

        <div>

            <asp:Button ID=”Button1″ runat=”server” Text=”Click me” OnClick=”Button1_Click” />

        </div>

    </form>

</body>

</html>

In this example, we have added the CodeBehind attribute to the @Page directive, which references the correct code-behind file (Default2.aspx.cs). We have also added an OnClick attribute to the Button control, which references the Button1_Click event handler method. Once you have made these changes, you should be able to build and run your application without getting the “Button1_Click is not a member of ASP.default2_aspx” error.

Apply for ASP.NET Certification Now!!

https://www.vskills.in/certification/certified-aspnet-programmer

Back to Tutorial

Characteristics of Derivatives
Application Deployment

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?