Click here to Skip to main content
15,892,674 members
Articles / Web Development / HTML

Leveraging .NET Components and IDE Integration: UI AOP in an MVC use case

Rate me:
Please Sign up or sign in to vote.
4.99/5 (125 votes)
28 Jun 200598 min read 354.1K   835   384  
An in-depth exploration of the features and the power of .NET Component Model architecture, its integration with the IDE at design-time and the possiblities it opens through extensions at run-time.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebComponents
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class Home : System.Web.UI.Page
	{
		#region Designer & Ctor stuff
		private System.ComponentModel.IContainer components;
		protected System.Web.UI.WebControls.Button btnSave;
		protected System.Web.UI.WebControls.TextBox txtID;
		protected System.Web.UI.WebControls.TextBox txtName;
		protected System.Web.UI.WebControls.TextBox txtCity;
		protected System.Web.UI.WebControls.TextBox txtState;
		protected System.Web.UI.WebControls.TextBox txtCountry;
		protected System.Web.UI.WebControls.Button btnLoad;
		protected PubsMvc.PublisherController controller;
		protected System.Web.UI.WebControls.Button btnDelete;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			//Response.Write("Service component site: ");
			//object service = this.Site.GetService(typeof(System.ComponentModel.Design.IServiceContainer));
			//Response.Write(service);
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			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.components = new System.ComponentModel.Container();
			System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
			this.controller = new PubsMvc.PublisherController(this.components);
			this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
			// 
			// controller
			// 
			this.controller.ConnectionString = ((string)(configurationAppSettings.GetValue("PubsConnection", typeof(string))));
			// 
			// ------------- Mvc Custom Code -------------
			// Controller code
			// 
			this.controller.ConfiguredViews.Add("txtName", new Mvc.Components.Controller.ViewInfo("txtName", "Text", "Publisher", "Name"));
			this.controller.ConfiguredViews.Add("txtID", new Mvc.Components.Controller.ViewInfo("txtID", "Text", "Publisher", "ID"));
			this.controller.ConfiguredViews.Add("txtCity", new Mvc.Components.Controller.ViewInfo("txtCity", "Text", "Publisher", "City"));
			this.controller.ConfiguredViews.Add("txtCountry", new Mvc.Components.Controller.ViewInfo("txtCountry", "Text", "Publisher", "Country"));
			this.controller.ConfiguredViews.Add("txtState", new Mvc.Components.Controller.ViewInfo("txtState", "Text", "Publisher", "State"));
			// Connect the controller with the hosting environment.
			new Mvc.Components.Adapter.WebFormsAdapter().Connect(this.controller, this, this.components);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		#endregion

		private void btnLoad_Click(object sender, System.EventArgs e)
		{
			controller.LoadPublisher();
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			controller.SavePublisher();
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			controller.DeletePublisher();
		}

	}
}

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


Written By
Software Developer (Senior)
Argentina Argentina

Comments and Discussions