CFF KB - Carrz-Fox-Fire Promotions Knowledge Base

CFF KB is all about 1 thing: The Sharing of Knowledge and the Power we gain from it.
  • Breadrumbs:
  • BC30451: 'xxxxxx' is not declared. It might be inaccessible due to its protection level.

  • CFF Knowledge Base - Share With Facebook CFF Knowledge Base - Share on Twitter CFF Knowledge Base - Share on Reddit CFF Knowledge Base - Share on Digg It CFF Knowledge Base - Share on Stumble Upon It CFF Knowledge Base - Share on Delicious
    Share With Friends (Updated 6-8-2010)
  • Article ID:
    6255
  • Date Created
    Thursday, June 16, 2022
  • Last Updated
    Thursday, June 16, 2022
  • This Article Has been Viewed
    763 times
  • Short Desc
    Why am I receiving the error, 'It might be inaccessible due to its protection level'?
  • Details
    IN ASP.NET, changing component names can sometimes cause the component not to be updated. If this happens you will experience the following error.

     
    BC30451: 'IDLabel' is not declared. It might be inaccessible due to its protection level.


    There are different scenarios that can cause this error to appear. In this article, we will only list them as we experience the error and correct them on our end. We will not take information from online sources and post it as our own errors.
  • Recreate Issue
    Scenario #1 and #2
    #1 Working in a Visual Studio Project
    #2 Working on a Visual Studio Website

    When the components name is ID.

    (Ignore the open and closing brackets in these examples)
    <%
    <asp:Label ID="ID" runat="server" Text="Label"></asp:Label>
    %>

    CodeFile is
    VB.NET
    ID.Text = "Page set to Upload!"
    C#
    ID.Text = "Page set to Upload!";
  • Resolve Issue
    Scenario #1
    (Working in a Visual Studio Project)
    In the above example, we see the ID is named [ID]. However, the name of the ID has changed.
    The new name is now IDLabel as demonstrated here.
    <%
    <asp:Label ID="IDLabel" runat="server" Text="Label"></asp:Label>
    %>

    But the name has not been updated in the Test.aspx.designer.vb or Test.aspx.designer.cs

    For VB.Net the Test.aspx.designer.vb will look like this. (Comments removed for space)
    VB.NET
     
    Partial Public Class Size
    Protected WithEvents form1 As Global.System.Web.UI.HtmlControls.HtmlForm
    Protected WithEvents fuUpload As Global.System.Web.UI.WebControls.FileUpload
    Protected WithEvents btnUpload As Global.System.Web.UI.WebControls.Button
    End Class


    For C# the Test.aspx.designer.cs will look like this.
     
    Partial Public Class Size{
    protected global::System.Web.UI.WebControls.HtmlForm form1;
    protected global::System.Web.UI.WebControls.FileUpload fuUpload;
    protected global::System.Web.UI.WebControls.Button btnUpload;
    protected global::System.Web.UI.WebControls.Label IDLabel;
    End Class}


    To correct the issue, we need to add the IDLabel to the list of components used by our project.
    VB.NET
    Protected WithEvents IDLabel As Global.System.Web.UI.WebControls.Label

    C#
    protected global::System.Web.UI.WebControls.Label IDLabel;

    Making the list of components looks like this.
    VB.NET
     
    Partial Public Class Size
    Protected WithEvents form1 As Global.System.Web.UI.HtmlControls.HtmlForm
    Protected WithEvents fuUpload As Global.System.Web.UI.WebControls.FileUpload
    Protected WithEvents btnUpload As Global.System.Web.UI.WebControls.Button
    Protected WithEvents IDLabel As Global.System.Web.UI.WebControls.Label
    End Class


    C#
     
    Partial Public Class Size{
    protected global::System.Web.UI.WebControls.HtmlForm form1;
    protected global::System.Web.UI.WebControls.FileUpload fuUpload;
    protected global::System.Web.UI.WebControls.Button btnUpload;
    protected global::System.Web.UI.WebControls.Label IDLabel;
    End Class}


    Then in our CodeFile
    VB.NET
    IDLabel.Text = "Page set to Upload!"
    C#
    IDLabel.Text = "Page set to Upload!";

    Scenario #2
    (Working on a Visual Studio Website)
    When working on a website project, you will not have the Test.aspx.designer.vb or Test.aspx.designer.cs files. Instead, you will need to update the ID name in the CodeFile.
    VB.NET
    ID.Text = "Page set to Upload!"
    C#
    ID.Text = "Page set to Upload!";
    to
    VB.NET
    IDLabel.Text = "Page set to Upload!"
    C#
    IDLabel.Text = "Page set to Upload!";
    To match our component ID name.
    <%
    <asp:Label ID="IDLabel" runat="server" Text="Label"></asp:Label>
    %>