实验成功方法有二:
方法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属性一定要被赋过值。
方法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属性一定要被赋过值。
本文介绍了在ASP.NET中动态设置网页标题的两种方法。方法一是在.aspx和.aspx.cs页操作,利用Label、TextBox等服务器控件赋值;方法二是往.aspx页拖入Literal控件,将其代码放于<title>标签间,在.aspx.cs页设置其值。
2950

被折叠的 条评论
为什么被折叠?



