1 / 21

Asp.Net Control Architecture

Asp.Net Control Architecture. Sundararajan Subramanian Software Development Engineer | Microsoft Sundararajan.Subramanian@microsoft.com. Agenda. Introduction What is a Custom Control? Custom Controls User Controls Server Controls User Controls – Demo

liv
Télécharger la présentation

Asp.Net Control Architecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Asp.Net Control Architecture Sundararajan Subramanian Software Development Engineer | Microsoft Sundararajan.Subramanian@microsoft.com

  2. Agenda • Introduction • What is a Custom Control? • Custom Controls • User Controls • Server Controls • User Controls – Demo • Server Controls – Rendering – Demo • Properties & State Management • Control Life Cycle. • Server Controls – Composite Controls • Event Handling • Summary

  3. 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.,

  4. Types of Controls • Declarative Markup in .Aspx Page • Common functionalities Refactored into a User Control - .ascx • Reusable behavior built /compiled and packaged as Server Control

  5. Ways to Author Custom controls • User Controls • Simple, declarative authoring model (.ascx file) • Scoped to a single application • Well suited to static content and layout • “Custom” or Compiled Controls • Code-based authoring model (.cs or .vb class file) • Easily shared across applications • Well suited to dynamic or programmatic generation of content and layout • More complex, but also more capabilities

  6. DEMO User Controls

  7. DEMO Custom Server control – Rendering Sample

  8. Which Base Class To Choose? • System.Web.UI.control • System.Web.UI.WebControls.WebControl • Derive from Existing Controls

  9. Properties • Getters And Setters • Allows the Client to set the properties at design time or runtime. • String _Text; • Public String Text{ • get { • return _Text; • } • Set { • _Text=Value; • } • }

  10. State Management • View State • Session State • Application State • Control state • Override Savecontrolstate and Loadcontrolstate • Custom State management • Override 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. Control Life Cycle Post Back Only

  13. Control Life Cycle …. Post Back Only

  14. Raising an Event • Define the EventArgs • Define the Event Delegate • Define a method that invokes the event Delegate public class LogOutEventArgs : EventArgs {...} public delegate void LogOutEventHandler(object sender,LogOutEventArgs e); protected virtual void OnLogOut(LogOutEventArgs e) { if (LogOut != null) { LogOut(this, e); } }

  15. DEMO Raising Events

  16. Composite controls • Based on object composition • Combining the existing controls and delegating the responsibility to the existing controls. • Reuses the feature of existing controls

  17. DEMO Composite Control Event Handling

  18. Performance Considerations • Use Event Properties for handling Events • Store only necessary information in State • Store very minimal information in Control state

  19. Summary • Controls provide ways to reuse functionality in web apps • Use User controls for within application usage • Create Specialized derived controls to make Incremental changes to existing controls • Use Composition to leverage existing controls to build more complex controls

  20. Contact • Contact me @ • http://blogs.msdn.com/sundararajan • Sundararajan.subramanian@microsoft.com

More Related