0

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;
Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40
xArd
  • 49
  • 11

2 Answers2

0

Define the btnModify_Click method.

void btnModify_Click(object sender, EventArgs e){
    // do something.
}
Rob Rodi
  • 3,476
  • 20
  • 19
  • The error occurs when i define the method :/ i check if its the same name and staff like that but still the same – xArd May 05 '12 at 14:37
0

Try using CodeFile instead of CodeBehind in page tag. CodeBehind requires the solution to be compiled. There could be something wrong in your code. After using CodeFile attribute in the page tag, put a break point on your button event handler and see if you still get that error.

Habib
  • 219,104
  • 29
  • 407
  • 436
  • Thanks Thanks Thanks!!!!!!! :) ,what is the difference between CodeBehind and CodeFile? – xArd May 05 '12 at 15:54
  • @xArd, check out this thread http://stackoverflow.com/questions/73022/codefile-vs-codebehind – Habib May 05 '12 at 18:53