我正在尝试创建一个 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/