简体   繁体   English

如何从app_code中的类设置母版页中的属性? 与asp.net C#

[英]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.

相关问题 ASP.Net c# - 如何在App_Code类中实例化WebUserControl的实例? - ASP.Net c# - How do I instantiate an instance of a WebUserControl from within a App_Code class? 为什么我不能在我的代码asp.net c#中使用app_code中的代码文件 - why I can't use code files from app_code in my code asp.net c# 我可以在ASP.NET网站的CodeFile之外的App_Code的C#文件中使用类/函数吗? - Can I use class/function in C# file in App_Code besides the CodeFile for an asp.net website? ASP.NET中的类App_Code中的局部类 - Class in ASP.NET Partial Class in App_Code 如何从C#App_Code类中获取当前页面的URL? - How can I get the URL of the current page from within a C# App_Code class? C#ASP.net如何从后面的代码访问新类,而不是保留在APP_CODE中,而是与后面的代码保留在同一文件夹中 - C# ASP.net How to access new classes from code behind, not kept in APP_CODE, but kept in same folder as code behind 在ASP.Net App_Code文件夹中混合C#和VB.Net - Mixing C# and VB.Net in ASP.Net App_Code folder app_code文件夹中的asp.net使用类 - asp.net use class in app_code folder 访问ASP.NET中App_Code中未声明的类 - Accessing a Class that is NOT declared in App_Code in ASP.NET ASP.NET C#:如何在 web.config 中调用 App_code 函数 - ASP.NET C#: How can I call App_code functions inside of web.config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM