master page

i have a master page and a content page

in my master page i got a label to keep the user name and user type

my problem is in the content page i need to get the user type.

so i follow this information and code to get values from master to content;

public string MasterPageLabelUserType
        get { return lblUserType.Text; }
        set { lblUserType.Text = value; }

<%@ MasterType VirtualPath="~/login/CPanel.master" %> 

Label1.Text = Master.MasterPageLabelUserType;

Open in new window

it works fine if i had a button and clicked it.

but does not work when the page loads?

i think because when the page loads lblUserType is not assigned so is null.

please can some one help me?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

trry putting this
 Label1.Text = Master.MasterPageLabelUserType;

Open in new window

in the Page_PreRender event
You need to create an OnLoad event on the page that needs user type data retrieved from the master.Check the events for the pages in the VisualWebDev at Events for the particulary page.
Alfred A.Commented:
You should be able to execute Label1.Text = Master.MasterPageLabelUserType; in Page_Load or Page_PreRender of your Content Page with no problem at all even if lblUserType.text is empty.

In the master page, where in the designer did you put the label control lblUserType?  You should be putting this outside of the Master Page's ContentPlaceHolder control/s.  If you put lblUserType label control inside of a ContentPlaceHolder, then you will get a null reference exception.

Even if you do the following in Page_Load, or Page_PreRender and place the label control inside the Master Page ContentPlaceHolder, you will still get a null reference exception:

Label1.Text = ((Label)Master.FindControl("lblUserType")).Text;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JCWEBHOSTAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.