KEMBAR78
Asp.Net Control Architecture | PPTX
Asp.Net Control ArchitectureSundararajan SubramanianSoftware Development Engineer |  MicrosoftSundararajan.Subramanian@microsoft.com
AgendaIntroductionWhat is a Custom Control?Custom Controls User ControlsServer ControlsUser Controls – DemoServer Controls – Rendering – DemoProperties & State ManagementControl Life Cycle.Server Controls – Composite ControlsEvent HandlingSummary
What is a Server Control?.Net component that is used to generate the user interface of an ASP.NET Web application.Eg: Label, GridView, etc.,
Types of ControlsDeclarative Markup in .Aspx Page Common functionalities Refactored into a User Control - .ascx Reusable behavior built /compiled and packaged as Server Control
Ways to Author Custom controlsUser ControlsSimple, declarative authoring model (.ascx file)Scoped to a single applicationWell suited to static content and layout“Custom” or Compiled ControlsCode-based authoring model (.cs or .vb class file)Easily shared across applicationsWell suited to dynamic or programmatic generation of content and layoutMore complex, but also more capabilities
User ControlsDEMO
Custom Server control – Rendering SampleDEMO
Which Base Class To Choose?System.Web.UI.controlSystem.Web.UI.WebControls.WebControlDerive from Existing Controls
Properties	Getters And SettersAllows the Client to set the properties at design time or runtime.String  _Text;Public String Text{get { return _Text;}Set { _Text=Value;}}
State ManagementView State Session StateApplication StateControl state Override Savecontrolstate and LoadcontrolstateCustom State managementOverride LoadViewstate and SaveviewState
State Management - Sample[ Bindable(true), Category("Appearance"),DefaultValue(""), Description(“...") ]public string Text {    get {        object o = ViewState[“Text"];        if (o == null)             return String.Empty;            else            return (string)o;    }    set {ViewState[“Text"] = value;    }}
Control Life CyclePost Back Only
Control Life Cycle ….Post Back Only
Raising an EventDefine the EventArgsDefine the Event DelegateDefine a method that invokes the event Delegatepublic class LogOutEventArgs : EventArgs {...}public delegate void LogOutEventHandler(object sender,LogOutEventArgs e);protected virtual void OnLogOut(LogOutEventArgs e) {        if (LogOut != null) {LogOut(this, e);        }    }
Raising EventsDEMO
Composite controlsBased on object compositionCombining the existing controls and delegating the responsibility to the existing controls.Reuses the feature of existing controls
Composite Control Event HandlingDEMO
Performance Considerations	Use Event Properties for handling EventsStore only necessary information in StateStore very minimal information in Control state
Summary	Controls provide ways to reuse functionality in web appsUse User controls for within application usageCreate Specialized derived controls to make Incremental changes to existing controlsUse Composition to leverage existing controls to build more complex controls
ContactContact me @ http://blogs.msdn.com/sundararajanSundararajan.subramanian@microsoft.com
Asp.Net Control Architecture

Asp.Net Control Architecture

  • 1.
    Asp.Net Control ArchitectureSundararajanSubramanianSoftware Development Engineer | MicrosoftSundararajan.Subramanian@microsoft.com
  • 2.
    AgendaIntroductionWhat is aCustom Control?Custom Controls User ControlsServer ControlsUser Controls – DemoServer Controls – Rendering – DemoProperties & State ManagementControl Life Cycle.Server Controls – Composite ControlsEvent HandlingSummary
  • 3.
    What is aServer Control?.Net component that is used to generate the user interface of an ASP.NET Web application.Eg: Label, GridView, etc.,
  • 4.
    Types of ControlsDeclarativeMarkup in .Aspx Page Common functionalities Refactored into a User Control - .ascx Reusable behavior built /compiled and packaged as Server Control
  • 5.
    Ways to AuthorCustom controlsUser ControlsSimple, declarative authoring model (.ascx file)Scoped to a single applicationWell suited to static content and layout“Custom” or Compiled ControlsCode-based authoring model (.cs or .vb class file)Easily shared across applicationsWell suited to dynamic or programmatic generation of content and layoutMore complex, but also more capabilities
  • 6.
  • 7.
    Custom Server control– Rendering SampleDEMO
  • 8.
    Which Base ClassTo Choose?System.Web.UI.controlSystem.Web.UI.WebControls.WebControlDerive from Existing Controls
  • 9.
    Properties Getters And SettersAllowsthe Client to set the properties at design time or runtime.String _Text;Public String Text{get { return _Text;}Set { _Text=Value;}}
  • 10.
    State ManagementView StateSession StateApplication StateControl state Override Savecontrolstate and LoadcontrolstateCustom State managementOverride LoadViewstate and SaveviewState
  • 11.
    State Management -Sample[ Bindable(true), Category("Appearance"),DefaultValue(""), Description(“...") ]public string Text { get { object o = ViewState[“Text"]; if (o == null) return String.Empty; else return (string)o; } set {ViewState[“Text"] = value; }}
  • 12.
  • 13.
    Control Life Cycle….Post Back Only
  • 14.
    Raising an EventDefinethe EventArgsDefine the Event DelegateDefine a method that invokes the event Delegatepublic class LogOutEventArgs : EventArgs {...}public delegate void LogOutEventHandler(object sender,LogOutEventArgs e);protected virtual void OnLogOut(LogOutEventArgs e) { if (LogOut != null) {LogOut(this, e); } }
  • 15.
  • 16.
    Composite controlsBased onobject compositionCombining the existing controls and delegating the responsibility to the existing controls.Reuses the feature of existing controls
  • 17.
  • 18.
    Performance Considerations Use EventProperties for handling EventsStore only necessary information in StateStore very minimal information in Control state
  • 19.
    Summary Controls provide waysto reuse functionality in web appsUse User controls for within application usageCreate Specialized derived controls to make Incremental changes to existing controlsUse Composition to leverage existing controls to build more complex controls
  • 20.
    ContactContact me @http://blogs.msdn.com/sundararajanSundararajan.subramanian@microsoft.com