Solved

access master page data

Posted on 2010-09-13
3
523 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 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

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