Click here to Skip to main content
15,895,656 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.4K   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 TitleViewer.
	/// </summary>
	public class TitleViewer : System.Web.UI.Page
	{
		private System.ComponentModel.IContainer components;
		protected System.Web.UI.WebControls.TextBox txtType;
		protected System.Web.UI.WebControls.TextBox txtNotes;
		protected System.Web.UI.WebControls.TextBox txtPrice;
		protected System.Web.UI.WebControls.TextBox txtDate;
		protected PubsMvc.PublisherController publisher;
		protected System.Web.UI.WebControls.TextBox txtTitle;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (Request.QueryString["id"] != null)
				publisher.LoadTitle(Request.QueryString["id"]);
		}

		#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.publisher = new PubsMvc.PublisherController(this.components);
			((System.Web.UI.IAttributeAccessor)(this.txtTitle)).SetAttribute("MVC_Controller", "publisher");
			((System.Web.UI.IAttributeAccessor)(this.txtTitle)).SetAttribute("MVC_Model", "Title");
			((System.Web.UI.IAttributeAccessor)(this.txtTitle)).SetAttribute("MVC_ModelProperty", "Title");
			((System.Web.UI.IAttributeAccessor)(this.txtTitle)).SetAttribute("MVC_ControlProperty", "Text");
			((System.Web.UI.IAttributeAccessor)(this.txtType)).SetAttribute("MVC_Controller", "publisher");
			((System.Web.UI.IAttributeAccessor)(this.txtType)).SetAttribute("MVC_Model", "Title");
			((System.Web.UI.IAttributeAccessor)(this.txtType)).SetAttribute("MVC_ModelProperty", "Type");
			((System.Web.UI.IAttributeAccessor)(this.txtType)).SetAttribute("MVC_ControlProperty", "Text");
			((System.Web.UI.IAttributeAccessor)(this.txtNotes)).SetAttribute("MVC_Controller", "publisher");
			((System.Web.UI.IAttributeAccessor)(this.txtNotes)).SetAttribute("MVC_Model", "Title");
			((System.Web.UI.IAttributeAccessor)(this.txtNotes)).SetAttribute("MVC_ModelProperty", "Notes");
			((System.Web.UI.IAttributeAccessor)(this.txtNotes)).SetAttribute("MVC_ControlProperty", "Text");
			((System.Web.UI.IAttributeAccessor)(this.txtPrice)).SetAttribute("MVC_Controller", "publisher");
			((System.Web.UI.IAttributeAccessor)(this.txtPrice)).SetAttribute("MVC_Model", "Title");
			((System.Web.UI.IAttributeAccessor)(this.txtPrice)).SetAttribute("MVC_ModelProperty", "Price");
			((System.Web.UI.IAttributeAccessor)(this.txtPrice)).SetAttribute("MVC_ControlProperty", "Text");
			((System.Web.UI.IAttributeAccessor)(this.txtDate)).SetAttribute("MVC_Controller", "publisher");
			((System.Web.UI.IAttributeAccessor)(this.txtDate)).SetAttribute("MVC_Model", "Title");
			((System.Web.UI.IAttributeAccessor)(this.txtDate)).SetAttribute("MVC_ModelProperty", "PublicationDate");
			((System.Web.UI.IAttributeAccessor)(this.txtDate)).SetAttribute("MVC_ControlProperty", "Text");
			// 
			// publisher
			// 
			this.publisher.ConnectionString = ((string)(configurationAppSettings.GetValue("PubsConnection", typeof(string))));
			// 
			// ------------- Mvc Custom Code -------------
			// Controller code
			// 
			this.publisher.ConfiguredViews.Add("txtType", new Mvc.Components.Controller.ViewInfo("txtType", "Text", "Title", "Type"));
			this.publisher.ConfiguredViews.Add("txtTitle", new Mvc.Components.Controller.ViewInfo("txtTitle", "Text", "Title", "Title"));
			this.publisher.ConfiguredViews.Add("txtNotes", new Mvc.Components.Controller.ViewInfo("txtNotes", "Text", "Title", "Notes"));
			this.publisher.ConfiguredViews.Add("txtPrice", new Mvc.Components.Controller.ViewInfo("txtPrice", "Text", "Title", "Price"));
			this.publisher.ConfiguredViews.Add("txtDate", new Mvc.Components.Controller.ViewInfo("txtDate", "Text", "Title", "PublicationDate"));
			// Connect the controller with the hosting environment.
			new Mvc.Components.Adapter.WebFormsAdapter().Connect(this.publisher, this, this.components);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#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 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