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

标签 c# asp.net c#-4.0 compiler-errors

我正在尝试创建一个 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 属性后,在您的按钮事件处理程序上放置一个断点,看看您是否仍然收到该错误。

    关于c# - 添加方法导致编译错误 C# ASP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10462833/

    相关文章:

    c# - 从同一 IIS 中的另一个网站访问网站文件夹

    c#-4.0 - 动态CRM插件下载Word文档

    c# - 具有动态类型的 Linq 查询

    javascript - 在 C#.net Winform 应用程序中获取和设置 CKEditor HTML

    c# - 任务并行库 (TPL) 中的线程同步

    c# - 在 .Net String.Format 中强制 double 正号

    c# - 后续的组合框没有加载我所做的更改

    asp.net - 如何通过 Atom 编辑器运行 ASP.NET 5 应用程序?

    asp.net - 延迟回发怎么办?

    javascript - 获取图像可见区域状态以将 Canvas 中的图像设置在先前拖动的位置