2010-04-09 36 views
0

我已經使用主頁創建了一個內容頁面。如何在內容頁面設置標題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 - 我的新標題

的變化請指點,使應該只有我的新標題標題內,沒有任何額外的像查詢字符串等

任何幫助,將不勝感激。

+0

你要爲標題在第一if條件...? – deostroll 2014-05-12 08:38:59

回答

5

如果您未在頁面上設置默認標題,頁面將顯示URL作爲標題。 圍棋設置在.aspx文件頁面標題:

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

我還在<%@ Page ...指令中設置了內容頁面中的標題。有同樣的問題。 – user255795 2010-04-09 13:02:54

+0

它必須發生在你遺漏的一些代碼中。在你的問題中沒有跡象表明它會是什麼。 – Codesleuth 2010-04-09 13:46:41

+0

有沒有進一步的建議? – user255795 2010-04-16 07:51:33

相關問題