dottext学习笔记2 master构造
2006-09-17 21:40
239 查看
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,使之为空操作,这样导致该控件的标签不会出现在用户页面里
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public ContentRegion() ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
base.BackColor = Color.WhiteSmoke;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
base.Width = new Unit("100%");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
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" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
case HandlerType.Direct:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
HandlerConfiguration.SetControls(context,items[i].BlogControls);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return (IHttpHandler)items[i].Instance();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
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;
}
引入自定义控件的名字空间,将用到该空间中的控件来构建页面。
<%@ 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,使之为空操作,这样导致该控件的标签不会出现在用户页面里
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public ContentRegion() ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
base.BackColor = Color.WhiteSmoke;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
base.Width = new Unit("100%");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
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" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
case HandlerType.Direct:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
HandlerConfiguration.SetControls(context,items[i].BlogControls);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return (IHttpHandler)items[i].Instance();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
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;
}
相关文章推荐
- dottext学习笔记3 URL重写
- dottext学习笔记4 登陆页面
- DotNet Compact Framework中位图资源的使用学习笔记
- CSS学习笔记:text-shadow
- JS学习笔记3 TextUtil.js
- h5学习笔记:weui text/template 使用
- jQuery-text()与val()方法区别 学习笔记六
- JQuery学习笔记(1):bind()、 html()、val()、text()方法
- restructuredText学习笔记
- Android开发学习笔记:TextView的属性详解
- CSS学习笔记:溢出文本省略(text-overflow)
- 5.5.vue入门基础学习笔记-基础指令介绍(其他绑定指令v-text v-html v-once v-pre v-cloak)
- jQuery学习笔记—— .html(),.text()和.val()的使用
- 【JfaceTextFramework学习笔记之四】TextViewer实现原理简单分析
- IOS学习笔记(6)label textField textview
- Dot Net FrameWork 4.0 学习笔记(3)
- cocos2d-x学习笔记3:CCTextFieldTTF的使用和再封装
- System.Text.Encoding 学习笔记
- qml学习笔记(六):可视化元素Text、Window
- JavaScript学习笔记——jquery中html()、text()、val()的区别