dottext学习笔记2 master构造

 
1         页面元素
引入自定义控件的名字空间,将用到该空间中的控件来构建页面。
<%@ Page language="c#" AutoEventWireup="false" Inherits="Dottext.Web.UI.Pages.DottextMasterPage"%>
<%@ Register TagPrefix="DT" Namespace="Dottext.Web.UI.WebControls" Assembly="Dottext.Web" %>
<HEAD>
<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>
<DT:MASTERPAGE id="MPContainer" runat="server">
       <DT:contentregion id="MPMain" runat="server">
              <asp:PlaceHolder id="CenterBodyControl" runat="server"></asp:PlaceHolder>
       </DT:contentregion>
</DT:MASTERPAGE>
 
除了上面这些控件,针对某些页面URL重写时会把一些控件名列表加入context中,在页面构建中将会加这些控件。
2         类分析
2.1            ContentRegion
[ToolboxData("<{0}:ContentRegion runat=server></{0}:ContentRegion>")]
 public class ContentRegion : System.Web.UI.WebControls.Panel
在其构造中设置背景。
重载 RenderBeginTag RenderEndTag ,使之为空操作,这样导致该控件的标签不会出现在用户页面里
public  ContentRegion()  {
            
base.BackColor = Color.WhiteSmoke;
            
base.Width = new Unit("100%");
        }
2.2            MasterPage : System.Web.UI.HtmlControls.HtmlContainerControl
页面元素构成是
2.2.1      AddParsedSubObject
重载解析页面函数。在构造函数解析控件时会别调用。该函数的功能是只把属于ContentRegion类型的对象加载进成员变量contents中。由于该函数被重载,contents中的内容不会加到Controls容器中。
能解析到的也只是其子,它的孙子或div包围的(也算是孙子吧)并不会解析到。
根据类分析,Master的子控件只能是ContentRegion,否则也会被忽略掉的。
2.2.2      在OnInit中控制该控件初始化需要两步
2.2.2.1   BuildMasterPage加载皮肤
根据context提取出skin,加载skin的TemplagteFile。把该控件中所有Visible的子控件加到当前的控件容器Controls里,同时把TemplagteFile中的所有子控件清除,最后增加没有子控件的TemplateFile: this.Controls.AddAt(0, this.template)。 注意,这些控件只是当前页面控件,嵌在层中或子控件中等并不会加进来。
2.2.2.2   BuildContents加载布局
foreach (ContentRegion content in this.contents) ,根据ID在MasterPage中寻找同名的Control region,先把 region里边的控件清除,把content中的Controls移除到region中来。

 2.3            DottextMasterPage : System.Web.UI.Page

InitializeBlogPage(),根据缓存中的控件名集合,加载相应skin目录下的控件。这些控件名,是UrlReWriteHandlerFactory.GetHandler()针对web.config对那些HandlerType.Direct的Handler类型进行设置的。
<HttpHandler pattern="/rss/.aspx$" type="...RssHandler, Dottext.Common" handlerType="Direct" />
<HttpHandler pattern="/CommentsRSS/.aspx$" type=".., .." handlerType="Direct" />   

{
case HandlerType.Direct:
HandlerConfiguration.SetControls(context,items[i].BlogControls);
return (IHttpHandler)items[i].Instance();        
}

1.根据context中的键值对,设置标题;获取控件URL重写配置中的控件列表,加入CenterBodyControl中。Control c = LoadControl(ControlLocation);
c.ID = Regex.Replace(control,"(.ascx)$",string.Empty,RegexOptions.IgnoreCase)+"1";
CenterBodyControl.Controls.Add(c);

2. 增加 RSS Link URL 属性
3         CSS
所有的子控件,div其位置均由CSS来决定的。
#leftcontent {
       position : absolute;
       top : 20px;
       left : 20px;     
       width : 220px;
       background-color : #FFFFFF;     
       border : 1px dotted #8B8D72;
       border-top: 8px solid #8B8D72;
       border-bottom: 8px solid #8B8D72;
      
       font-size:11px;      
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值