简体   繁体   English

ASP按钮找不到事件处理程序

[英]Asp button can't find eventhandler

I'm having issues using ASP to register an event on a button. 我在使用ASP在按钮上注册事件时遇到问题。 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. 基本上,它找不到onclick处理程序,但是我不知道为什么。

This is my asp file Permissions.aspx: 这是我的asp文件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: 而我的代码隐藏文件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: 在您的Page指令中,尝试更正Inherits属性:

Inherits="WebProj.Permissions"

This attribute should contain name of code behind class, which in your case is WebProj.Permissions (not WebProj._Default ). 此属性应包含类背后的代码名称,在您的情况下为WebProj.Permissions (而不是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). 请注意,此处指定的类应在CodeBehind属性(在您的情况下为Permissions.aspx.cs中指定的文件中定义。

You must use 您必须使用

    Inherits="WebProj.Permissions" 

Reason, you have the namespace WebProj and the class Permissions . 原因是,您具有名称空间WebProj类Permissions So inherit must use the same. 所以继承必须使用相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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