English 中文(简体)
添加方法
原标题:Adding method causes Compilation Error C# ASP

I am trying to create a webpage, but when i create a button and add a method to it a compilation error occurs, when i remove the method from the button it work fine i tried these steps

  1. tried delete page, and redo it from from beginning
  2. find the error CS1061 online

3.adding method to button with different methods i am exhausted try to find what is the error pls help me!

  Server Error in  /  Application.

    Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

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;
最佳回答

Try using CodeFile und CodeBehind in page tag. 守则要求汇编解决办法。 你的法典可能有些错误。 在使用“File”字塔后,就座标语向 your子事件手提了一个突破点,看看你是否仍然有这一错误。

问题回答

界定<代码>btnModification_Click方法。

void btnModify_Click(object sender, EventArgs e){
    // do something.
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签