设置属性值从内容页母版页 [英] 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.
我有一个字符串[]我确定需要什么样的角色来访问该页面的每个内容页面上设置RequiredRoles的。
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.
我将如何去管理呢?我想基本上每个页面有一个String [] RequiredRoles定义,母版页会加载这个每次通话和检查,看看是否用户是这些角色。
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.
推荐答案
创建您的母版页的属性并从内容页访问:
Create a property in your master page and you access it from content page:
母版页:
public partial class BasePage : System.Web.UI.MasterPage
{
private string[] _RequiredRoles = null;
public string[] RequiredRoles
{
get { return _RequiredRoles; }
set { _RequiredRoles = value; }
}
}
内容页:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load()
{
Master.RequiredRoles = new string[] { /*set appropriate roles*/ };
}
}
这篇关于设置属性值从内容页母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!