skip to Main Content

I am using Visual Studio 2019 to convert a .Net 4.0 Framework website to a web application.

I have done the conversion, however when I build the web application I get the error "The name ‘MessageLabel’ does not exist in the current context".

My code is as follows –

Offline.aspx:

<%@ Page Language="C#" MasterPageFile="~/MasterPageUnsecure.master" AutoEventWireup="true" CodeFile="Offline.aspx.cs" Inherits="Offline" %>

<asp:Content ContentPlaceHolderID="Main" runat="server">

    
        <div style=" margin-left:15px;">
        
            <asp:Label ID="Label1" runat="server" Text="This feature is offline" CssClass="pageHeader"></asp:Label><br />
            <br />
            <asp:Label ID="MessageLabel" runat="server" Text="Label">
                </asp:Label>
        </div>
 
</asp:Content>

And the codefile:

using System;

public partial class Offline : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MessageLabel.Text =
            "This part of the site is temporarily offline for maintenance and will be available for you to use again shortly.<br><br>"
            + "If you require further information please contact " + ApplicationLogicBLL.AdministratorsEmailAddress
            + " or call " + ApplicationLogicBLL.AdministratorsTelephoneNumber + ".";
    }
}

I have been looking online tryin change CodeFile to CodeBehind, didn’t work.

Any help would be gratefully appreciated.

Thanks

[UPDATE]

I now have –

using System;

namespace SSIRS_Web_Application
{
    public partial class Offline : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MessageLabel.Text =
                "This part of the site is temporarily offline for maintenance and will be available for you to use again shortly.<br><br>"
                + "If you require further information please contact " + ApplicationLogicBLL.AdministratorsEmailAddress
                + " or call " + ApplicationLogicBLL.AdministratorsTelephoneNumber + ".";
        }
    }
}

And –

<%@ Page Language="C#" MasterPageFile="~/MasterPageUnsecure.master" AutoEventWireup="true" CodeBehind="Offline.aspx.cs" Inherits="SSIRS_Web_Application.Offline" %>

<asp:Content ContentPlaceHolderID="Main" runat="server">

    <div style=" margin-left:15px;">
    
        <asp:Label ID="Label1" runat="server" Text="This feature is offline" CssClass="pageHeader"></asp:Label><br />
        <br />
        <asp:Label ID="MessageLabel" runat="server" Text="Label">
            </asp:Label>
    </div>

</asp:Content>
Still getting the same error

2

Answers


  1. You should use the CodeBehind attribute in your ASPX page, not CodeFile and the Inherits attribute points to the correct namespace and class name.
    Example:

    <%@ Page Language="C#" MasterPageFile="~/MasterPageUnsecure.master" AutoEventWireup="true" CodeBehind="Offline.aspx.cs" Inherits="YourNamespace.Offline" %>
    
    Login or Signup to reply.
  2. you will neeed to wrap your .cs file in a namespace aswell should fix it.

        namespace SSIRS_Web_Application
        {
         public partial class Offline : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                MessageLabel.Text =
                    "This part of the site is temporarily offline for maintenance and will be available for you to use again shortly.<br><br>"
                    + "If you require further information please contact " + ApplicationLogicBLL.AdministratorsEmailAddress
                    + " or call " + ApplicationLogicBLL.AdministratorsTelephoneNumber + ".";
            }
        }
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search