5

I'm getting a weird error. I have the following front-end code:

<%@ 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>

And I have the following backend code:

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";    
        }
    }
}

Designer file:

namespace development.nokernok {
    public partial class articleList {        
       protected global::System.Web.UI.WebControls.Label lblTest;
    }
}

And I get thiss error message:

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

I have other templates which works just fine. I just can't understand why I'm getting this error here.

Update 1:

I just added some more code.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Steven
  • 19,224
  • 47
  • 152
  • 257
  • the sample you've given seems fine, can you give a more detailed snippet? is your ViewState enabled? – hallie Jun 23 '10 at 08:49
  • Turn on tracing for your page ans see what/when happens. – H H Jun 23 '10 at 08:51
  • Hallie: Frontend or backend? And how can I check if my ViewState is enabled? Henk: I'm using Visual Web Developer 2008 Express Edition. I've not been able to turn on tracing. If you can help me with that, I would be extremely happy! – Steven Jun 23 '10 at 09:11
  • Steven, top of the aspx: `<%@ Page Language="C#" Trace="true" ...%>` and make sure it's not turned of in Web.Config – H H Jun 23 '10 at 10:06
  • ah, I was thinking of debugging. Will test trace. – Steven Jun 23 '10 at 13:50
  • What is in line 17 of articleList.aspx.cs? Something I don't know if it's wrong is that class articleList in the designer doesn't inherit from TemplatePage. – bloparod Jun 24 '10 at 03:15

3 Answers3

3

check if related .aspx.designer.cs have

protected global::System.Web.UI.WebControls.Label lblTest;
Saar
  • 8,286
  • 5
  • 30
  • 32
  • Yes, the designer file has this code: `protected global::System.Web.UI.WebControls.Label lblTest;` – Steven Jun 23 '10 at 09:04
2

Thanks for you help guys.

I got it working now. I deleted the file and created a new one. Then I added line by line.

I still don't know what went wrong. Looking at the code, it all seems pretty much the same as I started out with.

Steven
  • 19,224
  • 47
  • 152
  • 257
  • I upvoted this because it worked when I tried it in Localhost, but the problem was still there when I published it to the website. Too late to remove my vote now. –  Apr 01 '16 at 12:20
1

Is it a web app project (not a web site project)? If yes (no), delete *.designer.cs and after that - in the context menu of *.as*x file (your page or control) -> Convert to web application

abatishchev
  • 98,240
  • 88
  • 296
  • 433