MasterPage.cs :  » Build-Systems » Draco.NET » Wilson » MasterPages » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » Draco.NET 
Draco.NET » Wilson » MasterPages » MasterPage.cs
//**************************************************************//
// Paul Wilson -- www.WilsonDotNet.com -- Paul@WilsonDotNet.com //
// Feel free to use and modify -- just leave these credit lines //
// I also always appreciate any other public credit you provide //
//**************************************************************//
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.HtmlControls;

namespace Wilson.MasterPages{
  [ToolboxData("<{0}:MasterPage runat=server></{0}:MasterPage>"),
    ToolboxItem(typeof(WebControlToolboxItem)),
    Designer(typeof(ReadWriteControlDesigner))]
  public class MasterPage : HtmlContainerControl
  {
    private string templateFile;
    private string defaultContent;

    private Control template = null;
    private ContentRegion defaults = new ContentRegion();
    private ArrayList contents = new ArrayList();

    [Category("MasterPage"), Description("Path of Template User Control")] 
    public string TemplateFile {
      get { return this.templateFile; }
      set { this.templateFile = value; }
    }

    [Category("MasterPage"), Description("Control ID for Default Content")] 
    public string DefaultContent {
      get { return this.defaultContent; }
      set { this.defaultContent = value; }
    }

    public MasterPage() {
      this.templateFile = ConfigurationSettings.AppSettings["Wilson.MasterPages.TemplateFile"];
      this.defaultContent = ConfigurationSettings.AppSettings["Wilson.MasterPages.DefaultContent"];
      if (this.defaultContent == null) {
        this.defaultContent = "Content";
      }
    }

    protected override void AddParsedSubObject(object obj) {
      if (obj is ContentRegion) {
        this.contents.Add(obj);
      }
      else {
        this.defaults.Controls.Add((Control)obj);
      }
    }

    protected override void OnInit(EventArgs e) {
      this.BuildMasterPage();
      this.BuildContents();
      base.OnInit(e);
    }

    private void BuildMasterPage() {
      if (this.templateFile == "") {
        throw new Exception("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() {
      if (this.defaults.HasControls()) {
        this.defaults.ID = this.defaultContent;
        this.contents.Add(this.defaults);
      }

      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);
        }
      }
    }

    protected override void RenderBeginTag(HtmlTextWriter writer) {}
    protected override void RenderEndTag(HtmlTextWriter writer) {}
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.