Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version
Go to top

Declarative Programming--Unifying Form And Web Development

, , 23 Nov 2004
Use declarative programming to create UI's common for both Web and Form applets.
declarativeform.zip
bin
Debug
declarativeForm.exe.manifest
MyXaml.dll
App.ico
declarativeweb.zip
MyXaml.dll
// Copyright (c) 2004 Marc Clifton.  All Rights Reserved

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
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.Xml.Xsl;

using MyXaml;

namespace declarativeWeb
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Panel formPanel;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				SimpleCalc sc=new SimpleCalc();
				XmlDocument doc=LoadDocument();

				if (doc != null)
				{
					Parser parser=new Parser();
					Panel panel=(Panel)parser.LoadObject(doc, "Calc", sc, null);
					if (panel != null)
					{
						formPanel.Controls.Add(panel);
					}
				}

				Session["SimpleCalc"]=sc;
			}
			else
			{
				SimpleCalc sc=(SimpleCalc)Session["SimpleCalc"];
				XmlDocument doc=LoadDocument();

				if (doc != null)
				{
					Parser parser=new Parser();
					Panel panel=(Panel)parser.LoadObject(doc, "Calc", sc, null);
					if (panel != null)
					{
						formPanel.Controls.Add(panel);
					}
				}
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private XmlDocument LoadDocument()
		{
			XmlDocument doc=null;
			string path=MapPath("");
			
			try
			{
				doc=new XmlDataDocument();
				doc.PreserveWhitespace=true;
				doc.Load(path+"\\calcForm.xml");
				XslTransform xt=new XslTransform();
				xt.Load(path+"\\form2web.xslt");
				StringBuilder sb=new StringBuilder();
				StringWriter sw=new StringWriter(sb);
				xt.Transform(doc, null, new XmlTextWriter(sw), new XmlUrlResolver());

				doc=new XmlDocument();
				doc.LoadXml(sb.ToString());
				System.Diagnostics.Trace.WriteLine(sb.ToString());

			}
			catch(Exception ex)
			{
				Trace.Warn(ex.Message);
			}
			return doc;
		}
	}
}

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 Authors

Marc Clifton

United States United States
Marc is the creator of two open source projets, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website, www.marcclifton.com, where you will find many of his articles and his blog.
 
Marc lives in Philmont, NY.

J. Dunlap
Web Developer
United States United States
My main goal as a developer is to improve the way software is designed, and how it interacts with the user. I like designing software best, but I also like coding and documentation. I especially like to work with user interfaces and graphics.
 
I have extensive knowledge of the .NET Framework, and like to delve into its internals. I specialize in working with VG.net and MyXaml. I also like to work with ASP.NET, AJAX, and DHTML.

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 23 Nov 2004
Article Copyright 2004 by Marc Clifton, J. Dunlap
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid