有关模版MasterPage的问题

 

1.当有很多页的页头,页尾,或页的左,右相同时,这时应该用模版(MasterPage).

MasterPage 里有个容器<asp:ContentPlaceHolder ID="UserContentMain" runat="server" />;

每个页的内容都放在这个容器里.容器的外面就是这些页相同的部分.可以在这些外部放些共同用到的东西,比如css,js等等.

2.页面如何引用.

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/App_Masters/User.master" CodeFile="baomi.aspx.cs" Inherits="BottomLink_baomi" %>

<asp:Content ID="Content1" ContentPlaceHolderID="UserContentMain" Runat="Server">

页面的内容………

</asp:Content>

3.动态换MasterPage,也就是说(MasterPage)cs页来决定,aspx页给的是默认的.

比如说,未登陆是MasterPage1登陆后是MasterPage2;

Aspx里是MasterPageFile="~/App_Masters/ MasterPage1.master"(默认,或未登陆时)

Cs里是

protected void Page_PreInit(object sender, EventArgs e)//判断用哪个masterpage

    {

        if (Profile.UserId != Guid.Empty)//判断是否登陆

        {

            this.MasterPageFile = "~/App_Masters/MasterPage2.master";//登陆后.

        }

}

原文地址:https://www.cnblogs.com/qfb620/p/1098665.html