views:

15

answers:

1

Hello all! First time posting. :)

I'm a pretty new developer so I'm not well versed in common ASP.NET problems.

As a test, my boss asked me to convert a (not very critical) ASP.NET site from 1.1 to 4.0. Well, it's not extremely difficult and things are going well so far. However, I've hit a small snag. I keep getting a NullReferenceException when I run this code:

Public Property PageTitle() As String

    '===========================================================================
    'Exposes the PageTitle property of the child control.
    '===========================================================================
    Get
        Return lblPageTitle.Text
    End Get

    Set(ByVal Value As String)
        'TODO:  find out why this throws a NullReference exception
        lblPageTitle.Text = Value
    End Set

End Property

The Value part does have a string attached to it (literally :) but the lblPageTitle just won't set right.

More background if this helps: Before, this web user control had these in the codebehind, but they started throwing errors because they were already declared. Anyways, here they are:

Public Shared lblPageTitle As New Label
Public Shared lblUser As New Label
Public Shared lblLastLogin As New Label
Public Shared lblToday As New Label
Public Shared lblSiteTitle As New Label

Obviously, the New keyword might have helped in this situation somehow, but none of those other labels have caused any trouble.

I've tried doing this but it didn't work:

    Dim PageTitle As New Label
    PageTitle = TryCast(ucPageHeader.FindControl("lblTitle"), Label)
    If Not IsNothing(PageTitle) Then
        PageTitle.Text = sb.ToString()
    End If

Any ideas?

A: 

Those declarations you deleted are required SOMEWHERE. I've got a feeling you're using a web application project and your .designer.vb file has somehow got out of date. As a quick fix, toggle "Show all files" in your solution explorer (it's a little toolbar button just up on the top leftish of your sidebar) and expand the arrow beside the .ascx file you're working on. You should see a .ascx.vb file and a .ascx.designer.vb file. Without going into too much more detail, try deleting the designer.vb file, then right clicking on the .ascx and selecting "Convert to web application". Visual Studio will recreate your .designer.vb, hopefully with all control references intact.

Recommended reading: Code-Behind with VS 2005 Web Application Projects. It's for ASP.NET 2.0 but the same basic principles apply.

nizmow