简体   繁体   English

ASP.NET:如何在后台代码中的母版/页面之间传递标准信息?

[英]ASP.NET: How can I pass standard information between Masters/Pages in the code-behind?

I need my child pages to be able to set the values of certain properties of the Master page before loading. 我需要我的子页面能够加载之前设置母版页某些属性的值。

In other words, how my application builds the Master page for the client depends upon what properties are set by the child pages on the back-end. 换句话说,我的应用程序如何为客户端构建“母版”页面取决于后端子页面设置的属性。

For example: 例如:

public partial class mstrPage : System.Web.UI.MasterPage
{
    public int Rows { get; set; }
    public int Cols { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        /* Build a .NET two-dimensional-array of divs
             that is <Rows> tall and <Cols> wide. */
    }
}

In this example, the child page needs to set the values of <Rows> and <Cols> before Page_Load() is invoked for the Master. 在此示例中,子页面需要在为母版调用Page_Load()之前设置<Rows><Cols>的值。

This is fairly simple to accomplish with inheritance in OOP, but ASP.NET web pages do not "inherit" their master pages in the code-behind. 使用OOP中的继承来完成此操作相当简单,但是ASP.NET网页不会在其背后的代码中“继承”其母版页。

In the given example, what would the code-behind look like for the ASP.NET child page that sets these properties? 在给定的示例中,设置这些属性的ASP.NET子页面的代码背后是什么样?

Very simple... on the master page at the top, set the directive: 非常简单...在顶部的主页上,设置指令:

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

in the child content pages you can access the properties by typing: Master.PROPERTYNAME 在子内容页面中,您可以通过键入以下内容访问属性: Master.PROPERTYNAME

See: MSDN 请参阅: MSDN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Asp.NET 按钮与代码隐藏链接? - How to link Asp.NET Button with Code-behind? 我可以在 ASP.Net 项目的代码隐藏中使用 JSON.Stringify 吗? - Can I use JSON.Stringify in code-behind of an ASP.Net project? ASP.Net-需要单击代码后面的按钮,这样我才能弹出错误消息 - ASP.Net - need to click a button from the code-behind so I can pop an error message 我们如何从asp.net中的代码隐藏调用javascript函数? - How we can call javascript function from code-behind in asp.net? 如何从后面的代码中将CSS样式添加到ASP.NET UserControl? - How do I add CSS styles to an ASP.NET UserControl from the code-behind? 如何将javascript方法(JSON对象)的结果发送到asp.net Webform上的隐藏代码? - How do I send the results of a javascript method (JSON object) to the code-behind on asp.net webform? asp.NET Web 应用程序,如何与所有代码隐藏文件共享类? - asp.NET Web App, how do I share classes with all code-behind files? 从后台代码添加时,在父标签控件的标签之间添加asp.net标签 - Adding an asp.net label in between the tags of a parent label control when adding from the code-behind ASP.Net:ClientID在用户控件的代码隐藏中不正确 - ASP.Net: ClientID not correct in code-behind of a user control ASP.NET定义列表, <dl> ,在代码隐藏中 - ASP.NET definition list, <dl>, in the code-behind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM