實驗成功方法有以下幾種方法:
方法1.
首先:在.aspx頁:
<head> <title> <%=PageTitle %> </title> </head>
其次:在.aspx.cs頁:
public class news_view : System.Web.UI.Page { //用於動態設置頁面標題 protected string PageTitle; private void Page_Load(object sender, System.EventArgs e) { //動態設置網頁的標題title為顯示頁內容的“標題” PageTitle=lblBiaoTi.Text; }
注意:這里的lblBiaoTi是一個Label控件,也可以是TextBox控件或其它服務器控件。
PageTitle=lblBiaoTi.Text;句之前lblBiaoTi的Text屬性一定要被賦過值。
方法2:利用Literal控件
首先:往.aspx頁中拖入一個Literal控件。ID設為PageTitle。
其次:進入.aspx的HTML頁面,將剛加的Literal控件的代碼完全剪切並粘貼到<title>和</title>之間。
最后:在.aspx.cs頁面的適當位置,如PageLoad函數中設置PageTitle的值。
示例:
在.aspx中:
<Head> <title> <asp:Literal id="PageTitle" runat="server"></asp:Literal> </title>
在.aspx.cs中:
public class news_view : System.Web.UI.Page { //用於動態設置頁面標題 protected string PageTitle; private void Page_Load(object sender, System.EventArgs e) { //動態設置網頁的標題title為顯示頁內容的“標題” PageTitle=lblBiaoTi.Text;
}
注意:這里的lblBiaoTi是一個Label控件,也可以是TextBox控件或其它服務器控件。
PageTitle=lblBiaoTi.Text;句之前lblBiaoTi的Text屬性一定要被賦過值。
方法3.在后台頁面直接進行設置:
private void Page_Load(object sender, System.EventArgs e)
{
Page.Title = "標題";
}