【问题标题】:Title in nested ASP.NET Master Pages嵌套 ASP.NET 母版页中的标题
【发布时间】:2012-03-06 18:51:16
【问题描述】:

我无法设置 ASP.NET 页面的标签标题

我有嵌套的母版页。我可以成功设置标签图标,但标题总是显示“主页”。我做错了什么?

    <%@ Master Language="C#" AutoEventWireup="true"  CodeBehind="Topbar.master.cs" Inherits="WebApplication1.Masters.Topbar"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>SomeTitle</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
    <link href="~/Styles/public.css" rel="stylesheet" type="text/css" />    
    <link rel="Shortcut Icon" href="~/Images/ionicon.ico" />

    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>

</head>
<body>

....

    <%@ Master Language="C#" MasterPageFile="~/Masters/Topbar.Master" AutoEventWireup="true"
    CodeBehind="Public.Master.cs" Inherits="WebApplication1.PublicMaster" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <asp:ContentPlaceHolder ID="head" runat="server">


    </asp:ContentPlaceHolder>
</asp:Content>

【问题讨论】:

    标签: asp.net master-pages


    【解决方案1】:

    在内容页面上,您应该使用@Page 指令,您可以在其中设置页面标题:

    <%@ Page Language="C#" MasterPageFile="~/Master1.master" 
         AutoEventWireup="true" Title="Untitled Page"  %>
    

    【讨论】:

    • 啊!我看到我已经有了,设置为“主页”,它会覆盖主 标记。干杯! :)
    【解决方案2】:

    您也可以通过将此块保存在母版页代码文件中来从服务器端执行此操作

    string pageNM = Request.Url.ToString();
     if (pageNM.Contains("index.aspx"))
     {
     this.Page.Title = "My custom Index Page Title";
     }
    

    【讨论】:

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