Top Banner

Click here to load reader

Asp.Net Control Architecture

Jul 06, 2015

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 1. Asp.Net Control Architecture
    Sundararajan Subramanian
    Software Development Engineer |Microsoft
    [email protected]

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. User Controls
DEMO
7. Custom Server control Rendering Sample
DEMO
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. Raising Events
DEMO
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. Composite Control Event Handling
DEMO
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
[email protected]