Click here to Skip to main content
15,892,480 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 125.1K   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.Web;
using System.Reflection;

namespace BasePageFramework.SmartState
{
	/// <summary>
	/// Summary description for SmartApplicationBase.
	/// </summary>
	public class SmartApplicationBase : ISmartApplication
	{

		[field: NonSerialized()]
		private HttpApplicationState _appState = null;

		#region ISmartApplication Members

		public void FlushAppState()
		{
			CheckInit();
			_appState.Clear();
		}

		public void PersistToAppState()
		{
			CheckInit();
			
			_appState.Lock();
			
			//update the derived smartapplication object to the application state...
			foreach(PropertyInfo inf in this.GetType().GetProperties())
				this._appState[inf.Name] = inf.GetValue(this,null);
			
			_appState.UnLock();
		}

		public void SetApplicationState(System.Web.HttpApplicationState state)
		{
			_appState = state;
			//extract the values out of application state so our smart application object 
			//has everything it needs to be referenced in the page
			_appState.Lock();
			
			foreach(PropertyInfo inf in this.GetType().GetProperties())
				inf.SetValue(this,this._appState[inf.Name],null);
			
			_appState.UnLock();
		}

		private void CheckInit()
		{
			if(_appState == null)
				throw new InvalidOperationException("The SmartApplicationState must be initialized before it is accessed");
		}

		#endregion
	}
}

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