<DT:MASTERPAGE id="MPContainer" runat="server">
<DT:contentregion id="MPMain" runat="server">
<asp:PlaceHolder id="CenterBodyControl" runat="server"></asp:PlaceHolder>
</DT:contentregion>
</DT:MASTERPAGE>
控件<DT:MASTERPAGE id="MPContainer" runat="server"> 负责装载Template.ascx文件;
控件<DT:contentregion id="MPMain" runat="server">用于在Template.ascx控件中定位,其中<DT:contentregion id="MPMain" runat="server">的控件名字必须与
Template.ascx中的一个控件名字相对应。由此就实现了Default.aspx中的特定控件在Template.ascx中的定位。
假若有多个contentregion控件,在template.ascx中也要有多个相对应名字的控件
不过在default.aspx中的contentregion要是平行级别,不是牵套。
在页面类Dottext.Web.UI.Pages.DottextMasterPage中,实现了向<asp:PlaceHolder id="CenterBodyControl" runat="server"></asp:PlaceHolder>控件加载控件的
功能。而加载的控件都是从配置文件里通过url重写根据url的不同而读取的
附:
default.aspx
<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="Dottext.Web.UI.Pages.DottextMasterPage"%>
<%@ Register TagPrefix="DT" Namespace="Dottext.Web.UI.WebControls" Assembly="Dottext.Web" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title><asp:Literal ID="pageTitle" Runat="server" /></title>
<meta content=".Text" name="GENERATOR">
<link id="MainStyle" type="text/css" rel="stylesheet" runat="Server"/>
<link id="SecondaryCss" type="text/css" rel="stylesheet" runat="Server"/>
<link id="RSSLink" title="RSS" type="application/rss+xml" rel="alternate" runat="Server"/>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<DT:MASTERPAGE id="MPContainer" runat="server">
<DT:contentregion id="MPMain" runat="server">
<asp:PlaceHolder id="CenterBodyControl" runat="server"></asp:PlaceHolder>
</DT:contentregion>
</DT:MASTERPAGE></form>
</body>
</HTML>
Template.ascx
<%@ Register TagPrefix="uc1" TagName="Footer" Src="Footer.ascx" %>
<%@ Register TagPrefix="uc1" TagName="SiteCategory" Src="SiteCategory.ascx" %>
<%@ Register TagPrefix="uc1" TagName="PostsList" Src="PostsList.ascx" %>
<%@ Register TagPrefix="uc1" TagName="Header" Src="Header.ascx" %>
<%@ Register TagPrefix="uc1" TagName="SiteSearch" Src="SiteSearch.ascx" %>
<%@ Register TagPrefix="uc1" TagName="PagedPosts" Src="PagedPosts.ascx" %>
<%@ Register TagPrefix="uc1" TagName="SiteNavigate" Src="SiteNavigate.ascx" %>
<%@ Register TagPrefix="uc1" TagName="Syndication" Src="~/AggSite/Syndication.ascx" %>
<%@ Register TagPrefix="uc1" TagName="AggStats" Src="~/AggSite/AggStats.ascx" %>
<%@ Register TagPrefix="uc1" TagName="BlogList" Src="~/AggSite/BlogList.ascx" %>
<%@ Register TagPrefix="DT" Namespace="Dottext.Web.UI.WebControls" Assembly="Dottext.Web" %>
<%@ Register TagPrefix="uc1" TagName="FriendLink" Src="FriendLink.ascx" %>
<uc1:header id="Header1" runat="server"></uc1:header>
<div id="authors"><DT:CONTENTREGION id="LeftColumn" runat="server">
<uc1:SiteNavigate id="SiteNavigate1" runat="server"></uc1:SiteNavigate>
<uc1:SiteCategory id="SiteCategory1" runat="server"></uc1:SiteCategory>
<uc1:SiteSearch id="SiteSearch1" runat="server"></uc1:SiteSearch>
<uc1:Syndication id="Syndication1" runat="server"></uc1:Syndication>
<uc1:AggStats id="AggStats1" runat="server"></uc1:AggStats>
<uc1:FriendLink id="FriendLink1" runat="server"></uc1:FriendLink>
<uc1:BlogList id="BlogList1" title="博客排行榜" runat="server"></uc1:BlogList>
</DT:CONTENTREGION></div>
<div id="main"><DT:CONTENTREGION id="MPMain" runat="server"></DT:CONTENTREGION></div>
<div id="footer"><uc1:Footer id="Footer1" runat="server"></uc1:Footer></div>
PagePosts.ascx (Dottext.Web.UI.Pages.DottextMasterPage中加载的控件)
<%@ OutputCache Duration="60" VaryByParam="page;date;cate;onlytitle;cateid;group;id;author" VaryByCustom="Url" %>
<%@ Register TagPrefix="dt" Namespace="Dottext.Web.UI.WebControls" Assembly="Dottext.Web"%>
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="PagedPosts.ascx.cs" Inherits="Dottext.Web.AggSite.PagedPosts" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<h2><asp:literal id="CatalogTitle" runat="server"></asp:literal></h2>
<dt:pager id="ResultsPager" runat="server" CssClass="Pager" LinkFormatActive="{1}" UseSpacer="True"
DisplayMode="Block"></dt:pager>
<asp:repeater id="RecentPostsRepeater" runat="server">
<ItemTemplate>
<div class="post">
<h3>
<asp:HyperLink Runat = "server" NavigateUrl = '<%# BuildUrl(DataBinder.Eval(((RepeaterItem)Container).DataItem,"TitleUrl",null),DataBinder.Eval(((RepeaterItem)Container).DataItem,"Link",null),DataBinder.Eval(((RepeaterItem)Container).DataItem,"SourceUrl").ToString(),DataBinder.Eval(((RepeaterItem)Container).DataItem,"PostType").ToString()) %>' Text = '<%# DataBinder.Eval(((RepeaterItem)Container).DataItem,"Title") %>' ID="lnkTitle"/>
</h3>
<h4>
<asp:Literal runat = "server" Text = '<%# CheckLength(DataBinder.Eval(((RepeaterItem)Container).DataItem,"Body").ToString()) %>' ID="BlogContentLabel" />
</h4>
<p class="postfoot" align="right">
<asp:Literal runat = "server" Text = '<%# (DateTime.Parse(DataBinder.Eval(((RepeaterItem)Container).DataItem,"DateCreated",null))).ToString("yyyy-MM-dd HH:mm") %>' ID="Label5"/>
作者:
<asp:HyperLink Runat = "server" CssClass = "clsSubText" NavigateUrl='<%# GetBlogUrl() %>' Text = '<%# DataBinder.Eval(((RepeaterItem)Container).DataItem,"Author",null) %>' ID="Hyperlink3"/>
<asp:HyperLink runat = "server" CssClass = "CommentLink" NavigateUrl='<%# GetUrl()+"#Post" %>' Text = '<%# "【评论:"+DataBinder.Eval(((RepeaterItem)Container).DataItem,"FeedBackCount")+"】" %>' ID="lnkComments"/>【阅读:
<asp:Literal runat = "server" Text = '<%# DataBinder.Eval(((RepeaterItem)Container).DataItem,"ViewCount") %>' ID="Literal2"/>】
</p>
</div>
</ItemTemplate>
</asp:repeater>
<h6><dt:pager id="ResultsPager2" runat="server" CssClass="Pager" LinkFormatActive="{1}" UseSpacer="True"></dt:pager></h6>