Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Property Value on Master Page from Content Page

I need to pass data to a variable in my master page each time a page is loaded.

I have a string[] of RequiredRoles that I set on each content page defining what roles are required to access that page.

On my master page, I have a method that takes this array, and checks to see if the current user is in one or more of those roles.

How would I go about managing this? I basically want each page to have a String[] RequiredRoles defined, and the master page will load this on each call and check to see if the users are in those roles.

like image 457
WedTM Avatar asked Jul 02 '09 00:07

WedTM


People also ask

How do you access a public property defined in a master page from the content page?

To access members of a specific master page from a content page, you can create a strongly typed reference to the master page by creating a @ MasterType directive. The directive allows you to point to a specific master page. When the page creates its Master property, the property is typed to the referenced master page.

How master page and content pages are connected?

The master page establishes a layout and includes one or more ContentPlaceHolder controls for replaceable text and controls. The content page includes only the text and controls that are merged at run time with the master page's ContentPlaceHolder controls.


2 Answers

Typecast Page.Master to your master page so that you are doing something like:

((MyMasterPageType)Page.Master).Roles = "blah blah";
like image 93
NotMe Avatar answered Oct 11 '22 02:10

NotMe


Add page directive to your child page:

<%@ MasterType VirtualPath="~/MasterPage.master" %>

Then add property to your master page:

public string Section { get; set; }

You can access this property like this:

Master.Section = "blog";
like image 30
HasanG Avatar answered Oct 11 '22 03:10

HasanG