2010-06-23 15 views
5

Me aparece un error extraño. Tengo el siguiente código de front-end:¿Por qué obtengo esta System.NullReferenceException?

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

Y tengo el siguiente código de fondo: archivo

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

diseñador:

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

Y me da mensaje de error thiss:

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 

Tengo otro te mplates que funciona bien. Simplemente no puedo entender por qué estoy recibiendo este error aquí.

Actualización 1:

que acaba de añadir algo más de código.

+0

parece buena la muestra que ha dado, ¿puede darnos un fragmento más detallado? ¿está habilitado su ViewState? – hallie

+0

Active el rastreo para su página y vea qué y cuándo sucede. –

+0

Hallie: ¿Frontend o backend? ¿Y cómo puedo verificar si mi ViewState está habilitado? Henk: Estoy usando Visual Web Developer 2008 Express Edition. No he podido activar el rastreo. Si me pueden ayudar con eso, ¡me sentiría extremadamente feliz! – Steven

Respuesta

3

verificación si aspx.designer.cs relacionados tienen

protected global::System.Web.UI.WebControls.Label lblTest; 
+0

Sí, el archivo de diseñador tiene este código: 'protected global :: System.Web.UI.WebControls.Label lblTest;' – Steven

1

¿Es un proyecto de aplicación web (no es un proyecto de sitio web)? En caso afirmativo (no), elimine *.designer.cs y después de eso - en el menú contextual del archivo *.as*x (su página o control) ->Convert to web application

2

Gracias por su ayuda muchachos.

Lo tengo trabajando ahora. Eliminé el archivo y creé uno nuevo. Luego agregué línea por línea.

Aún no sé qué salió mal. Al mirar el código, todo parece más o menos el mismo con el que comencé.

+0

Volví a subir esto porque funcionaba cuando lo probé en Localhost, pero el problema todavía estaba allí cuando publiqué al sitio web. Demasiado tarde para quitar mi voto ahora. – jp2code

Cuestiones relacionadas