【问题标题】:change the master page body color from different pages when they load in vb.net在 vb.net 中加载时更改不同页面的母版页正文颜色
【发布时间】:2012-01-04 04:43:59
【问题描述】:

我有 10 个 aspx 页面 (junior_class_students1.aspx-...10.aspx)。它们的背面都有相同的母版页(class_students.master)。每次我加载一个页面时,我都希望母版页背景颜色更改为我可以为每页指定的颜色。 所以 ...students1.aspx 然后 .master ...students2.aspx 然后 .master ...students3.aspx 然后 .master

如何做到这一点?

【问题讨论】:

    标签: vb.net background master-pages


    【解决方案1】:

    请记住,内容持有者可以去页面中的任何位置。可以这样做:

    <div style="background-color:<asp:ContentPlaceHolder id="divColor" runat="server" />"></div>
    

    然后在你的页面中有这个:

    <asp:Content ID="divColorContent" ContentPlaceHolderID="divColor" Runat="Server">green</asp:Content>
    

    【讨论】:

    • 我很困惑..这会在每个新页面加载时更改母版页的正文颜色?
    • 母版页和使用它的页面是同一个页面。 ASP.NET 将它们组合成一个页面。以上内容最终会变成一页有
    【解决方案2】:

    CSS 类。

    您可以在 body 和 contentplaceholder 上放置一个填充 body 的 div。

    母版页

    <body>
    <asp:ContentPlaceHolder id="cph" runat="server" />
    </body>
    

    该 div 每页可以有一个唯一的 ID。

    内容页面

    <asp:Content id="cnt" ContentPlaceHolderID="cph">
        <div id="Page1" class="container">
          <!--Page Content-->
        </div>
    </asp:Content>
    

    那么 CSS 可能是这样的:

    div.container
    {
        width: 100%;
        height: 100%;
    }
    div#Page1
    {
        background-color: green;
    }
    div#Page2
    {
        background-color: blue;
    }
    ...
    

    【讨论】:

    • 等等。在 id="cnt" 的第二段代码上。在内容页面中,在我的情况下是 ..students1.aspx,2,3... 现在如果我给一个 div 以 100% 的高度和宽度,那将如何使母版页正文改变颜色?跨度>
    • 我的意思是你应该放置 div 来填充整个身体。您可以将正文放在内容页面中,但我更喜欢将表单放在我的母版页中。
    猜你喜欢
    • 2015-12-21
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    • 2014-02-22
    • 1970-01-01
    • 2014-04-16
    相关资源
    最近更新 更多