添加方法会导致编译错误 C# ASP
本文关键字:错误 ASP 编译 方法 添加 | 更新日期: 2023-09-27 18:33:20
我正在尝试创建一个webpage
,但是当我创建一个button
并向其添加method
时,compilation error occurs
,当我从按钮中删除method
时,它可以正常工作我尝试了这些步骤
- 尝试删除页面,然后从头开始重做
- 在线查找错误
CS1061
3.使用不同的方法添加按钮的方法 我筋疲力尽,试图找到错误是什么,请帮助我!
Server Error in '/' Application.
Compilation Error
说明:编译处理此请求所需的资源时出错。请查看以下特定错误详细信息并相应地修改源代码。
编译器错误消息: CS1061:"ASP.usermodification_aspx"不 包含"btnModify_Click"的定义,没有扩展方法 "btnModify_Click"接受类型的第一个参数 可以找到"ASP.usermodification_aspx"(您是否缺少使用 指令还是程序集引用?
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
。代码隐藏需要编译解决方案。您的代码中可能存在错误。在页面标记中使用 CodeFile 属性后,在按钮事件处理程序上放置一个断点,看看是否仍然收到该错误。
定义btnModify_Click
方法。
void btnModify_Click(object sender, EventArgs e){
// do something.
}