获取或者更改母版页标题

在定义好母版页以后,有时我们需要改变网页的标题但是如果直接在母版页中更改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标签内容即可 软件开发网 www.mscto.com
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
        <title>无标题页</title>
    </asp:Content>
posted on 2008-11-23 22:29  Right Now!JustDoIt!  阅读(688)  评论(0编辑  收藏  举报