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
Pagedirective try correcting theInheritsattribute:This attribute should contain name of code behind class, which in your case is
WebProj.Permissions(notWebProj._Default). Note that the class specified here should be defined in the file specified in theCodeBehindattribute (Permissions.aspx.csin your case).