Solved

access master page data

Posted on 2010-09-13
3
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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