Solved

access master page data

Posted on 2010-09-13
3
518 Views
Last Modified: 2013-11-08
hi EE,
I have the following line of code in a master file but when trying to access it within code I get null.

When debugging through the master file it has a value but when my new code gets executed the value is null.

can someone please advise me what im doing wrong?

many thanks,



// in master file
MyMasterPageModel.ViewDataKey = "MasterPageModel";
MyMasterPageModel model = ViewData[MyMasterPageModel.ViewDataKey] as MyMasterPageModel;  // model has a value

....


// in child file

if ((MyMasterPageModel )ViewData["MasterPageModel"])  // returns null ??
{
}

Open in new window

0
Comment
Question by:jimbona27
3 Comments
 
LVL 14

Expert Comment

by:existenz2
Comment Utility
Have a look at http://www.asp.net/mvc/tutorials/passing-data-to-view-master-pages-vb

It's not exactly what you are looking for, but it should give you some tips.
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
Comment Utility
0
 
LVL 1

Accepted Solution

by:
sweetsathish earned 500 total points
Comment Utility
Master pages and content pages do not share the same ViewState. If you are trying to pass something from the master page to the content page there are a couple of alternatives:

-> use this.Context.Items that is common to the entire site during an HTTP request
-> make a public property in the master page, use @MasterType in ContentPage. Set the value of the property as value in ViewState in Master Page's events and access them in the Content Page.
-> use Session
For setting the values and retrieving them you would need to play with the Master-Content page events carefully...
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now