實驗成功方法有二: 方法1. 首先:在.aspx頁: <HEAD> 。。。。。。。 </HEAD> 其次:在.aspx.cs頁: public class news_view : System.Web.UI.Page 。。。。 private void Page_Load(object sender, System.EventArgs e) 。。。。。。。 //動態設置網頁的標題title為顯示頁內容的“標題” 。。。 注意:這里的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 。。。。 private void Page_Load(object sender, System.EventArgs e) 。。。。。。。 //動態設置網頁的標題title為顯示頁內容的“標題” 。。。 注意:這里的lblBiaoTi是一個Label控件,也可以是TextBox控件或其它服務器控件。 PageTitle=lblBiaoTi.Text;句之前lblBiaoTi的Text屬性一定要被賦過值。 |
溫馨提示:喜歡本站的話,請收藏一下本站!