Mounir
Mounir

Reputation: 291

CS1061: Compilation Error Message

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)
        {
        } 
    }
}

Upvotes: 6

Views: 72159

Answers (2)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

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)

Upvotes: 1

Anders Abel
Anders Abel

Reputation: 69250

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.

Upvotes: 9

Related Questions