如何在内容页面asp.net中设置标题

时间:2010-04-09 08:17:16

标签: asp.net

我使用母版页创建了一个内容页面。

在母版页中,我为标题创建了以下标记:

<head id="Head1" runat="server">
    <title></title>   
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
</head>

在内容页面中,设置如下:

   protected void Page_Load(object sender, EventArgs e)
{

    if (!Page.IsPostBack)
    {
        if (String.IsNullOrEmpty(Request.QueryString["PatientRegistrationKey"]))
        {
           // ....
        }
        else
        {
            this.Page.Title = "My New Title";
            //....
        }
    }

虽然我也在运行时设置母版页如下:

 protected void Page_PreInit(Object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(Request.QueryString["PatientRegistrationKey"]))
            this.MasterPageFile = "~/MasterPages/A.master";
        else
            this.MasterPageFile = "~/MasterPages/B.master";
    }

在浏览器中打开此页面时,我得到了以下标题:

http://localhost:3562/?PatientRegistrationKey=0 - 我的新标题

请提供有关更改的建议,以便标题中只有 我的新标题 ,没有什么比查询字符串等更多。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:5)

如果您未在页面上设置默认标题,该页面将显示URL作为标题。 去设置.aspx文件中的页面标题:

<%@ Page Language="C#" MasterPageFile="..."
    AutoEventWireup="true" Title="My Default Title" %>