Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version
Go to top

FrameControl - Framework for creating web applications

, 25 Jul 2003
FrameControl is a framework that contains the code common for most of the web applications.
FrameControl_demo.zip
FrameControl1.dll
doc
banner.jpg
darkcorner.jpg
FrameControl1
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
FrameControl_src.zip
banner.jpg
darkcorner.jpg
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
obj
Debug
temp
TempPE
Release
FrameControl1.dll
FrameControl1.projdata
temp
TempPE
FrameControl1.csproj.user
FrameControl_install.zip
// Libraries in use. 
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Configuration;


namespace JobMorning
{ 
	/// <summary>
	/// A class inheriting from System.Web.UI.Page that is the central display page of the web application
	/// using the FrameControl framework.
	/// </summary>
	public class DisplayCentral : System.Web.UI.Page 
	{ 
		// Fields and Properties 
		private HtmlForm Form = new HtmlForm(); 
		private System.Web.UI.WebControls.Table Table1 = new Table();
		private System.Web.UI.WebControls.PlaceHolder menuPlaceHolder = new PlaceHolder();
		private System.Web.UI.WebControls.TextBox ctxtBox = new TextBox();
		private bool isPathUpdated;
		private System.Web.UI.WebControls.Label PathLabel = new Label();
		private Table Footer = new Table();
		private System.Collections.Hashtable h;


		// Constructor. 
		// ... 

		// Overridden CreateChildControls method. 
		protected override void CreateChildControls()
		{ 
			
			// Form. 
			this.Controls.Add(this.Form); 

			// Main region. 
			if ((string)Session["FormMethod"]=="GET")
			{
				this.Form.Method="GET";
			}
		
			this.Form.Controls.Add(menuPlaceHolder); 
			this.Form.Controls.Add(Table1); 

			this.Form.Controls.Add(Footer); 

			// Continue base implementation. 
			base.CreateChildControls(); 
		} 

		protected void UpdateFooter()
		{
			// Footer. 
			
			this.Footer.Rows.Add(new TableRow()); 
			TableCell cell0 = new TableCell();
			cell0.ColumnSpan=2;
			cell0.Style["Color"] = "Black";
			cell0.Style["Background-Color"] = "Gainsboro";
			this.Footer.Rows[0].Cells.Add(cell0); 
			this.Footer.Rows[0].Cells[0].Text="<B>FrameControl debugging information</B><BR/><HR/>";

			this.Footer.Rows.Add(new TableRow()); 
			TableCell cellTitle = new TableCell();
			cellTitle.Width=100;
			cellTitle.Style["Color"] = "Black";
			cellTitle.Style["Background-Color"] = "Gainsboro";
			cellTitle.Text="<b> User navigation path:</b>";
			this.Footer.Rows[1].Cells.Add(cellTitle);
			TableCell cell = new TableCell();
			cell.Width=400;
			cell.Style["Color"] = "Black";
			cell.Style["Background-Color"] = "Gainsboro";
			this.Footer.Rows[1].Cells.Add(cell); 
			this.Footer.Rows[1].Cells[1].Controls.Add(PathLabel);

			this.Footer.Rows.Add(new TableRow()); 
			TableCell cellTitle2 = new TableCell();
			cellTitle2.ColumnSpan=2;
			cellTitle2.Width=100;
			cellTitle2.Style["Color"] = "Black";
			cellTitle2.Style["Background-Color"] = "Gainsboro";
			cellTitle2.Text="<b> XML document in session:</b>";
			this.Footer.Rows[2].Cells.Add(cellTitle2);

			this.Footer.Rows.Add(new TableRow()); 
			TableCell cell3 = new TableCell();
			cell3.ColumnSpan=2;
			cell3.Style["Color"] = "Black";
			cell3.Style["Background-Color"] = "Gainsboro";
			cell3.Text= System.Web.HttpUtility.HtmlEncode(GetXmlContext());
			this.Footer.Rows[3].Cells.Add(cell3); 
		}

		/// <summary>
		/// The Page_Load method that should be called by the class inheriting from DisplayCentral.cs
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		public void Page_Load(object sender, System.EventArgs e)
		{

			// prevent any bug caused by the back button
			string strPostingPage = Request.Params["pagename"];
			if (strPostingPage!=null)
			{
				Session["currentPage"]=strPostingPage;
			}

			if (((string)Session["ClearPageCache"])=="YES")
			{
				Response.Buffer=true;
				Response.ExpiresAbsolute = System.DateTime.Now;
				Response.Expires = 0;
				Response.CacheControl = "no-cache";
			} // if (((string)Session["ClearPageCache"])=="YES")

			
			if (((string)Session["ERROR"])=="FALSE")
			{
				string strPathRequest = (string) Session["pathRequest"];
				if (!strPathRequest.Equals(""))
				{
					((JobMorning.SessionTransit)Session["SessionTransit"]).JumpPath(strPathRequest, "N");
					Session["pathRequest"] = "";
				} // if (!strPathRequest.Equals(""))
	
				
				string strPageRequest = (string) Session["pageRequest"];
				if (!strPageRequest.Equals(""))
				{
					((JobMorning.SessionTransit)Session["SessionTransit"]).JumpPage(strPageRequest);
					Session["pageRequest"] = "";
				} // if (!strPageRequest.Equals(""))

				
				h = new Hashtable();	
				// if the parameter path is not empty, take its value and jump
				// to the path value.
				
				// if the table has no child controls (empty table,
				// first loading of the DisplayCentral page), updates it.
				isPathUpdated = false;
				
				if (!Table1.HasControls())
				{
					UpdateControlArray();
				}
				
				UpdateFooter();
				
				if (((string)Session["BackButton"])=="NO")
				{
					string strDisBackBttn = 
						@"<script language=""JavaScript"">window.history.forward(1);</script>";
					if(!this.IsStartupScriptRegistered("Startup"))
						this.RegisterStartupScript("Startup",strDisBackBttn );
				} // if (((string)Session["BackButton"])=="NO")
			}
		}
		
	
		/// <summary>
		/// Get the XML description of the current page
		/// </summary>
		/// <returns>The XML returned contains all the controls description, their ID, their creation
		/// date and the data entered by the user if those controls are input controls.</returns>
		public string GetPageXml(ref Hashtable pageInputs)
		{
			
			// Clear the pageInputs Hashtable to delete previous values
			pageInputs.Clear();
			
			// Disable validators for PlaceHolders and create XML String
			string strPHField="<result>";
			IDictionaryEnumerator myEnumerator = h.GetEnumerator();
			while ( myEnumerator.MoveNext())
			{
				strPHField += ((JobMorning.ApplicationTransit)Application["ApplicationTransit"]).CreateXmlFlow((System.Web.UI.Control)h[myEnumerator.Key],ref pageInputs);
			}
			strPHField+="</result>";
			return strPHField;
		}

		/// <summary>
		/// UpdateControlArray resets the content of the page from the value of strPage (current page).
		/// </summary>
		public void UpdateControlArray()
		{
			// If the table already contains Controls, delete them
			// Delete also the HashTables describing these controls
			
			if (Table1.HasControls())
			{
				Table1.Rows.Clear();
				h.Clear();
				Footer.Rows.Clear();
				menuPlaceHolder.Controls.Clear();
			}
			
			// Fill the main table containing the .ascx controls
			string strPN = (String) Session["CurrentPage"];
			if(!isPathUpdated)
			{
				Session["UserTrack"] = Session["UserTrack"]+">"+strPN;
				isPathUpdated = true;
			}
			
			((JobMorning.SessionTransit)Session["SessionTransit"]).FillTable(this, ref Table1, ref menuPlaceHolder, ref h, strPN);
			
			// Get the key for tracing context and if it is
			// activated, add a link to the current context 
			string strContextDisplay =  ConfigurationSettings.AppSettings["TRACE_CONTEXT"];
			if (strContextDisplay.Equals("ON"))
			{
				
				PathLabel.Text=" User path = "+Session["UserTrack"];
				Footer.Visible=true;
				UpdateFooter();

			}
			else
			{
				Footer.Visible=false;
			}
			Session["currentMainPage"]=this;
		}
		

		// Overridden Render method. 
		protected override void Render(HtmlTextWriter writer) 
		{ 
			
			string curPageTitle = (string)Session["Title"];
			// Render the start HTML. 
			writer.Write("<html><head>");
			
			writer.Write("<title>"+curPageTitle+"</title></head>");
			// writer.Write(@"<body onunload=""setNewUrl();"">");

			writer.Write(@"<body>");
			
			
			this.RegisterHiddenField("pagename",(string)Session["currentPage"]);
			// Block to control if the Licence is respected
			bool isError=false;
			
			// Test if one XML file declaration has been forgotten in Web.config
			ArrayList configKeys = new ArrayList();
			configKeys.Add("APP_ALLPATHS");
			configKeys.Add("APP_STOREDPROCEDURES");
			configKeys.Add("APP_SAVEPOINTS");
			configKeys.Add("APP_PAGECONTROLS");
			string strKey;
			string strKeyDefined;
			string strDebug;
			bool isAllKeysDefined = true;
			foreach(object item in configKeys) 
			{
				strKey = item.ToString();
				strKeyDefined = strKey + "_DEFINED";
				strDebug = ((string)Application[strKeyDefined]);
				if (((string)Application[strKeyDefined])!="TRUE")
				{
					writer.Write((string)Application[strKeyDefined]);
					writer.Write("<BR/>");
					writer.Write("<HR/>");
					writer.Write("<BR/>");
					isError=true;
					isAllKeysDefined = false;
				} // if (((string)Application[strKeyDefined])!="TRUE")
			} // foreach(object item in configKeys)

			
			if (isAllKeysDefined)
			{
				if (((string)Application["ERROR"])!="FALSE")
				{
					writer.Write((string)Application["ERROR"]);
					writer.Write("<BR/>");
					writer.Write("<HR/>");
					writer.Write("<BR/>");
					isError=true;
				} // if (((string)Application["ERROR"])!="FALSE")

				if (((string)Session["ERROR"])!="FALSE")
				{
					writer.Write((string)Session["ERROR"]);
					writer.Write("<BR/>");
					writer.Write("<HR/>");
					writer.Write("<BR/>");
					isError=true;
				} // if (((string)Session["ERROR"])!="FALSE")

			

			} // if (isAllKeysDefined)

			if (!isError)
			{
				// End Block to control if the Licence is respected
				// Render the page contents. 
				base.Render(writer);
			} // if (!isError)

			// string strLinkContext;
			// strLinkContext = @"<A HREF=""javascript:window.open";
			// strLinkContext += @"('displayContext.aspx','mywindow',";
			// strLinkContext += @"'fullscreen=no,toolbar=no,status=no,";
			// strLinkContext += @"menubar=yes,scrollbars=yes,";
			// strLinkContext += @"resizable=yes,directories=yes,location=yes,";
			// strLinkContext += @"width=600,height=600');"">";
			// strLinkContext += @" View the context ";
			// strLinkContext += @"</A>";
			// writer.Write(strLinkContext);
			// Render the end HTML. 
			writer.Write("</body>");
			writer.Write("</html>"); 
		} 
		/// <summary>
		/// GetXmlContext returns a description of the XML document in Session.
		/// </summary>
		/// <returns>MCContext XML document contained in Session, and the
		/// current page structure. </returns>
		public string GetXmlContext()
		{
			string strReturn ="";
			XmlDocument allPages = (XmlDocument) Session["PageControls"];
			string strCurPage = (string) Session["CurrentPage"];
			string strXPath = "//Page[@Name='"+strCurPage+"']";		
			XmlNode nodeCurPage=allPages.DocumentElement.SelectSingleNode(strXPath);
			
			// string strHeader;
			// strHeader = @"<meta http-equiv=""Content-Type"" content=""text/xml; charset=utf-8"" >"; 
			// writer.Write(strHeader);
			strReturn += "<xml>"; 
			strReturn += "<result>";
			if (nodeCurPage!=null)
			{
				strReturn += nodeCurPage.OuterXml;
			}

			SessionTransit myST;
			myST = (SessionTransit)Session["SessionTransit"];
			if (myST!=null)
			{
				strReturn += myST.GetMCContext().OuterXml;
			}

			strReturn += "</result>";
			strReturn += "</xml>"; 	
			return strReturn;
		}

	} 
} 

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

S. Jehan

Japan Japan
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 26 Jul 2003
Article Copyright 2003 by S. Jehan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid