简体   繁体   中英

Asp button can't find eventhandler

I'm having issues using ASP to register an event on a button. It gives me the error:

CS1061: 'ASP.permissions_aspx' does not contain a definition for 'CreateEndUserClick' and no extension method 'CreateEndUserClick' accepting a first argument of type 'ASP.permissions_aspx' could be found (are you missing a using directive or an assembly reference?)

When I visit the page in a browser, it still compiles successfully. Basically it can't find the onclick handler, however I can't figure out why.

This is my asp file Permissions.aspx:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/MainLayout.master" AutoEventWireup="True"  CodeBehind="Permissions.aspx.cs" Inherits="WebProj._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:Button ID="Button_CreateEndUser" runat="server" OnClick="CreateEndUserClick" Text="Create New End User/Group" />
</asp:Content>

I removed some of the non relevant elements of the page obviously.

And my codebehind file Permissions.aspx.cs:

namespace WebProj
{
    public partial class Permissions : System.Web.UI.Page
    {
        protected global::System.Web.UI.WebControls.Button Button_CreateEndUser;

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void CreateEndUserClick(object sender, EventArgs e)
        {
            Button_CreateEndUser.Text = "Hamstertext";
        }
    }
}

I'm not sure why it's unable to find the function. Could it possibly be because I use content tags to place it inside a master file?

I'd greatly appreciate any help or points in the right direction on how to approach this problem.

Thanks for your time!

In your Page directive try correcting the Inherits attribute:

Inherits="WebProj.Permissions"

This attribute should contain name of code behind class, which in your case is WebProj.Permissions (not WebProj._Default ). Note that the class specified here should be defined in the file specified in the CodeBehind attribute ( Permissions.aspx.cs in your case).

You must use

    Inherits="WebProj.Permissions" 

Reason, you have the namespace WebProj and the class Permissions . So inherit must use the same.

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