技术开发 频道

ASP.NET Master Page改变内容页title方法


【IT168技术文档】

  在定义好母版页以后,有时我们需要改变网页的标题但是如果直接在母版页中更改title属性又会导致其他的内容页出现相同的title情况,VS2008中提供了母版页的新功能。
  1.通过内容页中的Page指令中Title属性改变内容页title:
<%@ Page Language=”C#” MasterPageFile=”~/MyMaster.master” Title=”My Title” %>
  2.通过编程改变:前提是<head>标志必须是运行在服务器端,即要给它加上runat="server"属性
void Page_Load() { ...... Page.Header.Title="My Title"; ...... }
  3.通过内容页的head占位符控件,在VS2008中添加的母版页会在头部有如下按商品asp:ContentPlaceHolder控件(把母版页的title标签拖到该控件内)
<asp:ContentPlaceHolder id="head" runat="server"> <title>无标题页</title> </asp:ContentPlaceHolder>
  而内容页往往会添加一个对应的asp:Content控件,只需要改变其中的title标签内容即可
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <title>无标题页</title> </asp:Content>
0
相关文章