Asp.Net Control Architecture

1,600 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,600
On SlideShare
0
From Embeds
0
Number of Embeds
70
Actions
Shares
0
Downloads
36
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Asp.Net Control Architecture

  1. 1. Asp.Net Control Architecture<br />Sundararajan Subramanian<br />Software Development Engineer | Microsoft<br />Sundararajan.Subramanian@microsoft.com<br />
  2. 2. Agenda<br />Introduction<br />What is a Custom Control?<br />Custom Controls <br />User Controls<br />Server Controls<br />User Controls – Demo<br />Server Controls – Rendering – Demo<br />Properties & State Management<br />Control Life Cycle.<br />Server Controls – Composite Controls<br />Event Handling<br />Summary<br />
  3. 3. What is a Server Control?<br />.Net component that is used to generate the user interface of an ASP.NET Web application.<br />Eg: Label, GridView, etc.,<br />
  4. 4. Types of Controls<br />Declarative Markup in .Aspx Page <br />Common functionalities Refactored into a User Control - .ascx <br />Reusable behavior built /compiled and packaged as Server Control<br />
  5. 5. Ways to Author Custom controls<br />User Controls<br />Simple, declarative authoring model (.ascx file)<br />Scoped to a single application<br />Well suited to static content and layout<br />“Custom” or Compiled Controls<br />Code-based authoring model (.cs or .vb class file)<br />Easily shared across applications<br />Well suited to dynamic or programmatic generation of content and layout<br />More complex, but also more capabilities<br />
  6. 6. User Controls<br />DEMO<br />
  7. 7. Custom Server control – Rendering Sample<br />DEMO<br />
  8. 8. Which Base Class To Choose?<br />System.Web.UI.control<br />System.Web.UI.WebControls.WebControl<br />Derive from Existing Controls<br />
  9. 9. Properties <br />Getters And Setters<br />Allows the Client to set the properties at design time or runtime.<br />String _Text;<br />Public String Text{<br />get { <br />return _Text;<br />}<br />Set {<br /> _Text=Value;<br />}<br />}<br />
  10. 10. State Management<br />View State <br />Session State<br />Application State<br />Control state <br />Override Savecontrolstate and Loadcontrolstate<br />Custom State management<br />Override LoadViewstate and SaveviewState<br />
  11. 11. State Management - Sample<br />[ Bindable(true), Category("Appearance"),<br />DefaultValue(""), Description(“...") ]<br />public string Text {<br /> get {<br /> object o = ViewState[“Text"];<br /> if (o == null) <br /> return String.Empty; <br /> else<br /> return (string)o;<br /> }<br /> set {<br />ViewState[“Text"] = value;<br /> }<br />}<br />
  12. 12. Control Life Cycle<br />Post Back Only<br />
  13. 13. Control Life Cycle ….<br />Post Back Only<br />
  14. 14. Raising an Event<br />Define the EventArgs<br />Define the Event Delegate<br />Define a method that invokes the event Delegate<br />public class LogOutEventArgs : EventArgs {...}<br />public delegate void LogOutEventHandler(object sender,LogOutEventArgs e);<br />protected virtual void OnLogOut(LogOutEventArgs e) {<br /> if (LogOut != null) {<br />LogOut(this, e);<br /> }<br /> }<br />
  15. 15. Raising Events<br />DEMO<br />
  16. 16. Composite controls<br />Based on object composition<br />Combining the existing controls and delegating the responsibility to the existing controls.<br />Reuses the feature of existing controls<br />
  17. 17. Composite Control Event Handling<br />DEMO<br />
  18. 18. Performance Considerations <br />Use Event Properties for handling Events<br />Store only necessary information in State<br />Store very minimal information in Control state<br />
  19. 19. Summary <br />Controls provide ways to reuse functionality in web apps<br />Use User controls for within application usage<br />Create Specialized derived controls to make Incremental changes to existing controls<br />Use Composition to leverage existing controls to build more complex controls<br />
  20. 20. Contact<br />Contact me @ <br />http://blogs.msdn.com/sundararajan<br />Sundararajan.subramanian@microsoft.com<br />

×