0

我正在尝试创建一个webpage,但是当我创建一个并向它button添加一个时,当我从按钮中删除它时它工作正常我尝试了这些步骤methodcompilation error occursmethod

  1. 尝试删除页面,并从头开始重做
  2. CS1061在线查找错误

3.用不同的方法向按钮添加方法我已经筋疲力尽了,试着找出错误是什么,请帮助我!

  Server Error in '/' Application.

    Compilation Error

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

编译器错误消息:CS1061:“ASP.usermodification_aspx”不包含“btnModify_Click”的定义,并且找不到接受“ASP.usermodification_aspx”类型的第一个参数的扩展方法“btnModify_Click”(您是否缺少 using 指令或装配参考?)

    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;
4

2 回答 2

0

定义btnModify_Click方法。

void btnModify_Click(object sender, EventArgs e){
    // do something.
}
于 2012-05-05T14:35:28.207 回答
0

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

于 2012-05-05T15:07:14.917 回答