📄 masterpage.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using Club.Framework.Configuration;
namespace Club.Common.WebUI
{
/// <summary>
/// 页面容器
/// </summary>
[
ToolboxData("<{0}:MasterPage runat=server></{0}:MasterPage>"),
ToolboxItem(typeof(WebControlToolboxItem)),
Designer(typeof(ReadWriteControlDesigner))
]
public class MasterPage:System.Web.UI.HtmlControls.HtmlContainerControl
{
private string templateFile = null;
private Control template = null;
private ArrayList contents = new ArrayList();
//private const string SkinPath = "{0}/{1}/PageTemplate.ascx";
[Category("MasterPage"), Description("Path of Template User Control")]
public string TemplateFile
{
get
{
return this.templateFile;
}
set { this.templateFile = value; }
}
public MasterPage() {}
protected override void AddParsedSubObject(object obj)
{
if (obj is ContentRegion)
{
this.contents.Add(obj);
}
}
protected override void OnInit(EventArgs e)
{
this.BuildMasterPage();
this.BuildContents();
base.OnInit(e);
}
private void BuildMasterPage()
{
if (this.TemplateFile == null || this.TemplateFile == string.Empty)
{
throw new ApplicationException("TemplateFile Property for MasterPage must be Defined");
}
this.template = this.Page.LoadControl(this.TemplateFile);
this.template.ID = this.ID + "_Template";
int count = this.template.Controls.Count;
for (int index = 0; index < count; index++)
{
Control control = this.template.Controls[0];
this.template.Controls.Remove(control);
if (control.Visible)
{
this.Controls.Add(control);
}
}
this.Controls.AddAt(0, this.template);
}
private void BuildContents()
{
foreach (ContentRegion content in this.contents)
{
Control region = this.FindControl(content.ID);
if (region == null || !(region is ContentRegion))
{
throw new Exception("ContentRegion with ID '" + content.ID + "' must be Defined");
}
region.Controls.Clear();
int count = content.Controls.Count;
for (int index = 0; index < count; index++)
{
Control control = content.Controls[0];
content.Controls.Remove(control);
region.Controls.Add(control);
}
}
}
//removes this controls ability to render its own start tag
protected override void RenderBeginTag(System.Web.UI.HtmlTextWriter writer) {}
//removes this controls ability to render its own end tag
protected override void RenderEndTag(System.Web.UI.HtmlTextWriter writer) {}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -