我收到一个奇怪的错误。我有以下前端代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/nokernok/MasterPages/nokernok.Master" AutoEventWireup="true" CodeBehind="articleList.aspx.cs" Inherits="development.nokernok.articleList" %>
<%@ Register TagPrefix="EPiServer" Namespace="EPiServer.WebControls" Assembly="EPiServer" %>
<asp:Content ID="Content2" ContentPlaceHolderID="LeftContentPlaceHolder" runat="server">
<asp:Label ID="lblTest" runat="server" />
</asp:Content>
我有以下后端代码:
using System;
using System.Web;
using EPiServer;
using EPiServer.Core;
using development.NaafLibrary;
namespace development.nokernok
{
public partial class articleList : TemplatePage
{
protected void Page_Load(object sender, EventArgs e)
{
lblTest.Text = "TEEEEEEEEEEEST";
}
}
}
设计器文件:
namespace development.nokernok {
public partial class articleList {
protected global::System.Web.UI.WebControls.Label lblTest;
}
}
而且我收到这条错误消息:
Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
[NullReferenceException: Object reference not set to an instance of an object.]
development.nokernok.articleList.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\naaf\nokernok\articleList.aspx.cs:17
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
我还有其他工作正常的模板。
我只是不明白为什么我在这里遇到这个错误。
更新1 :
我刚刚添加了一些代码。
最佳答案
检查相关的.aspx.designer.cs是否具有
protected global::System.Web.UI.WebControls.Label lblTest;