Jatin Asija
Jatin Asija

Reputation: 128

Master.FindControl giving NullReferenceException

I am trying this

if (!IsPostBack)
    {
        Label theLabel = Master.FindControl("HeadingLabel") as Label;
        if (theLabel != null)
        {
            theLabel.Text = "Our Valuable Customers ";
        }
    }

i am getting a NullRefernceException error ,i am following a video series ,so i am doing the same ,but not able to run the code.He is is using .Net version =2.0 and i am using 4.0.

here is code for my master page

<asp:Label ID="HeadingLabel" runat="server" Font-Bold="True"Text="Online Shopping Website"></asp:Label>

Upvotes: 0

Views: 264

Answers (1)

Luaan
Luaan

Reputation: 63732

Looks like Master is null. If so, the page you're on isn't actually based on the master page.

Make sure the aspx actually has a master page specified in the @Page directive.

Upvotes: 1

Related Questions