【问题标题】:Reading and appending to master page titles?阅读并附加到母版页标题?
【发布时间】:2023-04-01 22:45:01
【问题描述】:

我要做的是读取当前母版页的标题,并从子页的代码隐藏中附加一些内容。

我尝试使用:

this.Master.Page.Title.ToString()

但它返回 null。有什么想法吗?

在母版页中,我是这样设置标题的:

<head runat="server">
    <title>The Magic Finger - Web Design</title>
    <link href="App_Themes/Style.css" rel="stylesheet" type="text/css" />
</head>

【问题讨论】:

  • 如果您的代码在页面内,请使用Title = "Some title"; 如果您在母版页内,请使用Page.Title = "Some title";
  • 这并不能解决您的问题,但 Master.Page 指的是在 Master 内部呈现的 Page 控件。即:(this == this.Master.Page)。

标签: asp.net master-pages


【解决方案1】:

改用Page.Title,标题由内容页设置。

【讨论】:

  • 我想要做的是追加到标题。因此,如果在母版页中的标题是“测试”,我希望在子页面中添加“主页”,从而产生最终标题“测试主页”。
【解决方案2】:

在您的母版页中正常设置页面标题。在您的子页面中,使用

    Me.Master.Page.Title &= " - This text will be appended"

重要提示:确保在子页面的 .aspx 中没有“标题”作为属性。如果你有这个:

    <%@ Page Title="" Language=""

确保移除 title 属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多