Solved

access master page data

Posted on 2010-09-13
3
522 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
ID: 33660368
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
ID: 33660377
0
 
LVL 1

Accepted Solution

by:
sweetsathish earned 500 total points
ID: 33670391
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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