Valerie Meunier

Valerie Meunier

  • 957
  • 693
  • 72.8k

Label1 in aspx not accessible due to protection level

Dec 30 2022 10:59 AM

Hi

this code gives the error "Label1 is inaccessible due to its protection level" in the line in bold. How can i fix that?

Thanks

V

aspx file

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" CodeBehind="tijden.aspx.cs" Inherits="tijdrit.Tijdrit" %>
...
<asp:Label ID="Label1" runat="server"></asp:Label>
...

code-behind

using System; using System.Web.UI;

namespace tijdrit
{
    public partial class Tijdrit : Page
    {
        public names = "Bob";
    }

    class Test
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Tijdrit tr = new Tijdrit();
            tr.Label1.Text = tr.names;
        }
    }
}

 


Answers (1)