Click here to Skip to main content
15,887,683 members
Articles / Web Development / ASP.NET

Building a Better ASP.NET 1.1 BasePage Framework

Rate me:
Please Sign up or sign in to vote.
4.52/5 (27 votes)
5 Dec 2005CPOL35 min read 125K   2.1K   156  
This is a journey on how to build a better Base page. The result of this will be a reusable framework that you can use to create as many Base pages as you like (on many different sites) and still have something that will keep the designers on your team happy.
using System;
using System.Reflection;
using HtmlUI = System.Web.UI.HtmlControls;
using WebCtlUI = System.Web.UI.WebControls;
using WebUI = System.Web.UI;

namespace BasePageFramework
{
	/// <summary>
	/// Summary description for MasterServerForm.
	/// </summary>
	public class BaseServerForm : HtmlUI.HtmlForm
	{
		
		private WebCtlUI.PlaceHolder _uiTemplatePlcHldr = new WebCtlUI.PlaceHolder();
		
		internal BaseServerForm(HtmlUI.HtmlForm oldFrm,IBaseTemplate uiTemplate)
		{
			foreach(string key in oldFrm.Attributes.Keys)
				this.Attributes.Add(key,oldFrm.Attributes[key]);

			System.Type frmTp = oldFrm.GetType();
			
			//move the controls first - so they are located in the main form before we
			//rip apart the htmlform via reflection
			while(oldFrm.Controls.Count > 0)
				uiTemplate.ContentArea.Controls.Add((System.Web.UI.Control)oldFrm.Controls[0]);

			//copy the old form's values into our new form...
			foreach(FieldInfo fields in frmTp.GetFields(BindingFlags.Public | 
				BindingFlags.NonPublic | 
				BindingFlags.Instance))
				this.GetType().GetField(fields.Name,
					BindingFlags.Public | 
					BindingFlags.NonPublic | 
					BindingFlags.Instance).SetValue(this,fields.GetValue(oldFrm));
			
			this._uiTemplatePlcHldr.Controls.Add((System.Web.UI.Control)uiTemplate);
			this.Controls.Add((System.Web.UI.Control)this._uiTemplatePlcHldr);
		
		}
		
		public IBaseTemplate BaseTemplate
		{
			get
			{
				return (IBaseTemplate)_uiTemplatePlcHldr.Controls[0];
			}
		}
	}
	
	


}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Priority Courier Experts
United States United States
software developer for about 25 years now.

Comments and Discussions