我正在使用Visual Studio 2019将.Net 4.0 Framework网站转换为Web应用程序。
我已经完成了转换,但是当我构建Web应用程序时,我得到错误“名称'MessageLabel'在当前上下文中不存在”。
我的代码如下-
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>
代码文件:
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 + ".";
}
}
我一直在网上寻找试图改变CodeFile到CodeBehind,没有工作。
任何帮助将不胜感激。
谢谢
[更新]
我现在有-
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 + ".";
}
}
}
还有-
<%@ 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>
仍然得到同样的错误
2条答案
按热度按时间qv7cva1a1#
您应该在ASPX页面中使用
CodeBehind
属性,而不是CodeFile
,Inherits
属性指向正确的命名空间和类名。范例:7eumitmz2#
你将需要 Package 你的.cs文件在一个命名空间以及应该修复它。