[英]How to set property in master page from class in app_code? with asp.net c#
How do I set a property in a master page from a class in app_code? 如何通过app_code中的类在母版页中设置属性? with asp.net c#
与asp.net C#
my master page: 我的母版页:
private int styleGroup;
public int StyleGroup
{
get { return styleGroup; }
set { styleGroup = value; }
}
how to I set StyleGroup from a class in the app_code? 如何从app_code中的类设置StyleGroup? something like this, but it doesn't work:
像这样的东西,但是不起作用:
Page currentPage = (Page)HttpContext.Current.Handler;
currentPage.Master.StyleID = 5;
thanks 谢谢
You have to cast the MasterPage of current to you MasterPage Class, something like this 您必须将当前的MasterPage转换为MasterPage类,例如
Page currentPage = (Page)HttpContext.Current.Handler;
((YourMasterPageClass)currentPage.Master).StyleID = 5;
将Page指针传递给app_code类函数,或在app_code中的类中设置Page成员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.