c# - 添加方法导致编译错误 C# ASP

我正在尝试创建一个 webpage ,但是当我创建 button并添加 method给它一个compilation error occurs ,当我删除 method从按钮它工作正常
我尝试了这些步骤

  • 尝试删除页面,并从头开始重做
  • 找到错误 CS1061在线

  • 3.用不同的方法为按钮添加方法
    我很累尝试找出错误是什么,请帮助我!
      Server Error in '/' Application.
    
        Compilation Error
    

    说明:在编译服务此请求所需的资源期间发生错误。请查看以下特定错误详细信息并适当修改您的源代码。

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


        Source Error:
    
    
            Line 38:         SelectCommand="SELECT RoleName FROM aspnet_Roles"></asp:SqlDataSource>
            Line 39:     <br />
            Line 40:     <asp:Button ID="btnModify" runat="server" Text="Modify" 
            Line 41:         onclick="btnModify_Click" />
            Line 42: 
    
    namespace RentACar
     {
        public partial class UserModification : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void btnModify_Click(object sender, EventArgs e)
            {
                GridViewRow row = gvUserRoles.SelectedRow;
    
                string username = row.Cells[0].Text;
                 string role = row.Cells[1].Text;
                 Roles.RemoveUserFromRole(username, role);
                string choosenrole = dllUserRoles.SelectedValue.ToString();
                Roles.AddUserToRole(username, choosenrole);
    
            }
        }
    }`
    
          <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="UserModification.aspx.cs" Inherits="RentACar.UserModification" %>
    <asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    
     <asp:Button ID="btnModify" runat="server" Text="Modify" 
            onclick="btnModify_Click" />
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Security;
    

    最佳答案

    尝试使用 CodeFile而不是 CodeBehind在页面标签中。 CodeBehind 需要编译解决方案。您的代码可能有问题。在页面标签中使用 CodeFile 属性后,在您的按钮事件处理程序上放置一个断点,看看您是否仍然收到该错误。

    https://stackoverflow.com/questions/10462833/

    相关文章:

    ruby - 为什么在编译ruby-1.9.3-p125时出现clang错误?

    testing - Flex Builder : Asset file or directory n

    iphone - 如何解决iPhone应用程序hpple HTML解析 'libxml/tree.h

    apache-flex - 类mx.core::DesignLayer could not be f

    visual-studio-2010 - VS2010 Express 中的 Boost - 重新定

    actionscript-3 - 1120 : Access of undefined proper

    c++ - 在UNIX上 “internal compiler error: storage fai

    compiler-errors - 添加平移和缩放错误

    c# - 将Gridview导出到Excel文件-错误

    xml - 构建SLN : CS0008 - CS0115的奇怪错误