Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CS1061: Compilation Error Message

Tags:

c#

asp.net

i have added a linkbutton to my page and get error when debugging says:

CS1061: 'ASP.uilayer_test_aspx' does not contain a definition for 'lbl_Click' and no extension method 'lbl_Click' accepting a first argument of type 'ASP.uilayer_test_aspx' could be found (are you missing a using directive or an assembly reference?)

.aspx contains :

<asp:LinkButton ID="lbl" runat="server" OnClick="lbl_Click">LinkButton</asp:LinkButton>

page diretive :

<%@ Page Language="C#" MasterPageFile="~/UILayer/UI.Master" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApp.UILayer.Test" Title="Untitled Page" %>

.cs contains :

namespace WebApp.UILayer
{
    public partial class Test : System.Web.UI.Page
    {
        private void lbl_Click(object sender, EventArgs e)
        {
        } 
    }
}
like image 487
Mounir Avatar asked Jul 17 '11 12:07

Mounir


2 Answers

You have to make lbl_Click protected and not private.

The reason for this is that an own class, called like ASP.uilayer_test_aspx is created from the aspx source. This class inherits from your Test class. Private methods are not visible to child classes, so it has to be protected.

like image 84
Anders Abel Avatar answered Nov 10 '22 02:11

Anders Abel


Because you have set the click handler lbl_Click modifier as private, you have to set it as Protected OR Public. Since the aspx file inherited the cs class, and private member can't be accessed.

This

 private void lbl_Click(object sender, EventArgs e)

should be like..

 protected void lbl_Click(object sender, EventArgs e)
like image 21
Muhammad Akhtar Avatar answered Nov 10 '22 03:11

Muhammad Akhtar