• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

ASP.NET: Accessing Functions/variables from Master Page

Hmongkeysauce

Senior member
Hi there,

I'm a rookie at this ASP.NET stuff. I've created a Master Page, that grabs a GET variable and sets a few global variables soft of speak. All the variables in this page are private, but I provided public functions to get those variables. However, I cannot retrieve these variables from the content pages using the public functions. I've included the Master Page directive at the top of the .aspx file:

<%@ MasterType TypeName="masterpage" %>

and still nothing. It's not giving me an error, I'm just retrieving null data. What gives?

Also, let's say if i want to create a small CMS application for this website. I've located all the files in a different folder called CMS. Should I add a new web.config file in this folder to protect all files in this folder or can I do this from the main website's web.config? Thanks in advance.

EDIT: ASP.NET 2.0 framework with C# language
 
From your content pages, you can reference Master.your_variable or Master.your_function using the Master object.

techfuzz
 
This is how I have done it in the past. First you need to cast the Page's MasterPage to be of your type of masterpage, so the IDE can intellisense the added functions.

myMasterPage m = (myMasterPage)Page.MasterPage
myMasterPage.GetVariable()
 
If it's compiling but you are getting nulls back, then you need to look at when in the page lifecycle you are calling the functions on the Master, and where the variables are stored. View state gets loaded at a certain point, etc. Post the relevant code from the master and content page and we'll take a look at it.
 
Back
Top