zoukankan      html  css  js  c++  java
  • asp.net设置标题 兼MasterPage得使用

    <%@ Page Language="C#" MasterPageFile="~/MasterPage/Common.master" AutoEventWireup="true" CodeFile="SceneList.aspx.cs" Inherits="Scene_SceneList" Title="韶关旅游通---旅游景区列表" %>


     

            
    this.Master.Page.Header.Title = "aa";
            
    this.Page.Title = "bb";

     

    内容页一般不需要cs文件,单独成一个文件,然后使用USER_CONTROL

     

    =============================

    一 设置Title

         
    1 如果想所有使用了masterpage的页面都是用一个title ,可以在masterpage页中设置title,并将内容页中的title去掉,否则内容页中的title会将masterpage中的title覆盖。

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MasterpageTest.aspx.cs" Inherits="MasterpageTest" Title="Test"%>
     改成

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MasterpageTest.aspx.cs" Inherits="MasterpageTest" %>
    2 如果想每个页面中使用不同等title就比较简单,在内容页中设置就可以,masterpage中的title不用去管 ,应为最终会被内容页中的覆盖掉。

     

    二 在内容页取 masterpage中的属性和字段

         在内容页中取masterpage中的属性或字段应该是比较常用的。创建一个masterpage页MasterTest.master 和内容页Test.aspx,在MasterTest.master的后台代码中添加一个属性,如下


       
    private string m_Name; 

        
    public string Name 

        { 

            
    get { return m_Name; } 

            
    set { m_Name = value; } 

        } 



    然后在内容页的后台代码中你会发现不能访问masterpage中的属性,这时切换到内容页的源里 在上面添加 


     

    <%@ MasterType VirtualPath="~/MasterTest.master" %>
    再切换到后台中 就可以访问masterpage中的属性了。

    三 masterpage页的作用范围

         
    1 页面级

        通常情况下我们使用masterpage都是页面级的,就是在每个内容页中都会来指定masterpage的名字,通过MastPageFile属性来设置,如下


    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master"  %>
    2 应用程序级

    这中就是只需在webconfig文件中做相应配置,全站所有的内容页都会引用设置的masterpage,如在webconfig中添加如下代码


        
    <configuration> 
            
    <system.web> 
                
    <pages masterPageFile="~/Test.master" /> 
            
    </system.web> 
        
    </configuration>
     这样在内容页中就不用再去设置MastPageFile属性了,所有的内容页都会使用Test.master  。如果有些页面比较特殊需要用其他的masterpage ,可以这是MastPageFile属性,将会覆盖在webconfig中的配置。

    用这种方法也可以对某些文件夹中的所有文件来进行设置,配置如下


       
    <configuration> 
            
    <location path="Admin"> 
                
    <system.web> 
                    
    <pages masterPageFile="~/ Test.master " /> 
                
    </system.web> 
            
    </location> 
        
    </configuration>
    Location的path属性设置路径

     

    ================================

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

      在定义好母版页以后,有时我们需要改变网页的标题但是如果直接在母版页中更改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> 




    本文来自CSDN博客,转载请标明出处:http:
    //blog.csdn.net/cxzhq2002/archive/2008/12/17/3539685.aspx
  • 相关阅读:
    例20:希尔排序
    例19:直接插入排序
    例14:计算某日是该年的第几天
    为自己
    hdoj--1027--Ignatius and the Princess II(dfs)
    UESTC--758--P酱的冒险旅途(模拟)
    nyoj--990--蚂蚁感冒(模拟)(思维题)
    历届试题 邮局(dfs+剪枝)
    历届试题 数字游戏
    历届试题 回文数字
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1597159.html
Copyright © 2011-2022 走看看