實驗成功方法有二:
方法1.
首先:在.aspx頁:
<HEAD>
<title>
<%=PageTitle %>
</title>
。。。。。。。
</HEAD>
其次:在.aspx.cs頁:
public class news_view : System.Web.UI.Page
{
。。。。。。。。。。。。
//用于動態(tài)設(shè)置頁面標(biāo)題
PRotected string PageTitle;
。。。。
private void Page_Load(object sender, System.EventArgs e)
{
。。。。。。。
//動態(tài)設(shè)置網(wǎng)頁的標(biāo)題title為顯示頁內(nèi)容的“標(biāo)題”
PageTitle=lblBiaoTi.Text;
。。。
注意:這里的lblBiaoTi是一個Label控件,也可以是TextBox控件或其它服務(wù)器控件。
PageTitle=lblBiaoTi.Text;句之前l(fā)blBiaoTi的Text屬性一定要被賦過值。
方法2:利用Literal控件
首先:往.aspx頁中拖入一個Literal控件。ID設(shè)為PageTitle。
其次:進入.aspx的HTML頁面,將剛加的Literal控件的代碼完全剪切并粘貼到<title>和</title>之間。
最后:在.aspx.cs頁面的適當(dāng)位置,如PageLoad函數(shù)中設(shè)置PageTitle的值。
示例:
在.aspx中:
<Head>
<title>
<asp:Literal id="PageTitle" runat="server"></asp:Literal>
</title>
在.aspx.cs中:
public class news_view : System.Web.UI.Page
{
。。。。。。。。。。。。
//用于動態(tài)設(shè)置頁面標(biāo)題
protected string PageTitle;
。。。。
private void Page_Load(object sender, System.EventArgs e)
{
。。。。。。。
//動態(tài)設(shè)置網(wǎng)頁的標(biāo)題title為顯示頁內(nèi)容的“標(biāo)題”
PageTitle=lblBiaoTi.Text;
。。。
注意:這里的lblBiaoTi是一個Label控件,也可以是TextBox控件或其它服務(wù)器控件。
PageTitle=lblBiaoTi.Text;句之前l(fā)blBiaoTi的Text屬性一定要被賦過值。
新聞熱點
疑難解答