SlideShare a Scribd company logo
ASP.NET 2.0
Advanced Server Controls
Daniel Fisher(lennybacon)
newtelligence® AG
2
About me
• Software Engineer, newtelligence AG
• Developer
• Consultant
• Trainer
• Author for Developer Magazines
• Expert & Editor for CodeZone.de
• IIS, ADO.NET …
• Leader of INETA UG VfL-NiederRhein
• CLIP Member
3
The Top 10 for better Webs
• 1. Creating an n-Tier Design
• 2. Working with Application Settings
• 3. Creating Maintainable User Interfaces
• 4. Creating Common Page Code
• 5. Tracking Users' Actions
• 6. Notifications of Exceptions
• 7. Using State Properly
• 8. Handling Unexpected Errors Gracefully
• 9. Assigning Roles and Securing Web Pages
• 10. There was no #10 ;-)
4
Maintainable User Interfaces
• It’s about reusability
• Html mark-up
• Server side code
• Client side scripts
5
ASP.NET Server Controls
• Compiled code that can be reused in any
ASP.NET web application.
• Classes contained in the namespace
System.Web.UI.WebControls are Server
Controls, developed by Microsoft.
• System.Web.UI.WebControls.Textbox
• (and many, many more)
• Use inheritance - all server controls come from
System.Web.UI.WebControls.Control
6
Server Controls Usage
• Register Assembly, NS and TagPrefix
• Use the Control
<%@ Register Assembly=“MyAssembly”
Namespace=“MyNamespace” TagPrefix=“MyPrefix” %>
<MyPrefix:MyControl runat=“server” id=“MyControl1” />
7
Server Controls Pro‘s
• Encapsulate logic in reusable
abstractions.
• Clean mechanism to divide work across a
team
• Market growth of 3rd
party products
• Allows ISPs to provide even more value to
for use in personal websites.
8
Server Controls Con‘s
• No visual way of developing server
controls, generated via code.
9
Something new …
• Java Server Faces lent concepts from
ASP.NET ;-)
Quelle: Birgit Hauer
10
Why Create Controls on your own
• Once did something twice?
• You need the functionality of two or more
controls working in tandem, without having to
write the logic in the web application.
• Existing server control almost meets your needs,
but only almost
• None of the existing server controls meet your
needs.
11
Lifecycle of a control
Instantiate : Constructor
Initialize : OnInit method and Init Event
Begin Tracking View State : TrackViewState
Load View State : LoadViewState method
Load Postback Data : IPostBackDataHandler.LoadPostdata method
Load: OnLoad method and Load event
Raise Changed Events : IPostBackDataHandler.RaisePostDataChangedEvent method
Raise Postback Event : IPostBackEventHandler.RaisePostBackEvent method
PreRender : OnPreRender method and PreRender event
Save View State : SaveViewState method
Render : Render method
Unload : OnUnload method and Unload event
Dispose : Dispose Method
12
Processing
• Control creation within the method
CreateChildControls()
• All display logic (aside from the necessary items
in above step) should be done in the method
OnPreRender().
• Rendering
• Custom: Override Render() method and provide
custom rendering logic
• Composite: Combining multiple controls into one
server control – Nothing to do?
13
Resources
• Strings
• Javascript
• Images
• HttpHandlers - later
14
Demo
• Resources
15
Properties
• Set variables to influence its
rendering.
• Almost all properties should be stored
within View State?
16
ViewState
• ViewState is used to track and restore the state
values of controls that would otherwise be lost
• Base64 encoded - not easily readable, but not
encrypted!
• What to store
• Integers
• Strings
• Floats
• Decimals
• Arrays of the data types stated above
17
ViewState in code
[Bindable(false),Category(“Appearance”),
DefaultValue(“This is the default text.”),
Description(“The text of the custom
control.”)]
public virtual string Text
{
get
{
object o = ViewState[“Text”];
if(o != null)
return (string) o;
else
return “This is the default text.”;
}
set { ViewState[“Text”] = value; }
}
18
ViewState Concepts
Send Request
Send Response
Send Request
Send Response
Ping Pong on the wire?
19
ViewState alternatives
• Query Request.Form and
Request.QueryString on your own
• Use local fields – most times they
work fine
20
Server Controls - Events
• Event Handling is the best way of letting users
tap into the processes of your control.
• Providing events like Click for when a button is
clicked, or SelectedIndexChanged when a new
item has been selected in a drop down list
enables developers to program in a very object
oriented manner.
21
Events in code
• Custom event eventargs and handler
• The On[Event] Method
• Raising an Event
public class MyEventArgs : EventArgs {
public MyEventArgs(string prop1, string prop2) { ... }
}
public delegate void MyEventHandler(object sender, MyEventArgs e);
public event MyEventHandler ItemChanged;
protected virtual void OnItemChanged(MyEventArgs e) {
if(Events != null) {
MyEventHandler eh = (MyEventHandler) Events[MyItemChangedEvent];
if(eh != null)
eh(this, e);
}
}
OnItemChanged(new MyEventArgs(“prop1”, “prop2”));
22
Demo
• Events and delegates
• EventControl
23
The downside - Postbacks
• Implement the IPostBackEventHandler
• Create an event field
• Create methods to relate to the event
24
Postbacks - Alternatives
• Server side only events
• AJAX
• Response.Redirect(
http://example.org);
• <a href=“…“>link</a>
25
Demo
• Server side only events
• WaitScreen
26
AJAX
• AsyncrounousJavascriptAndXml
27
AJAX in code
var request = new Request();
function _getXmlHttp(){
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
var progids =["Msxml2.XMLHTTP“,"Microsoft.XMLHTTP"];
for (i in progids){
try{
return new ActiveXObject(progids[i])
}
catch (e){}
}@end @*/
try{
return new XMLHttpRequest();
}catch (e2){ return null; }
}
28
Demo
• AJAX, Response.Redirect()
• UserManagement
29
30
Demo
• <a href=“…“>link</a>
• Forum
31
Databound Controls
• ObjectDataSource
• SqlDataSource
• …
• Abstract way to access data
• A lot of overhead but a standard way…
• Who is your target?
32
Databound in code
private ITemplate _itemTemplate;
public ITemplate ItemTemplate{
get{return _itemTemplate;}
set{_ itemTemplate=value;}
}
protected override void CreateChildControls(){
CreateControlHierarchy(true);
}
protected virtual void CreateControlHierarchy(bool dBind){
LoadFromDataSource();
foreach (object r in _dataSource){
RepeaterItem item1 =
CreateItem(ListItemType.Item, dataBind, r);
}
}
private RepeaterItem CreateItem(…)
{
_itemTemplate.InstantiateIn(item);
Controls.Add(item);
}
33
Demo
• Databound Controls
• DataBoundControl
34
Hirarchical Controls
• Navigations, Tabs …
• ITemplate
• ChildControls
35
Hirarchical Controls - ChildControls
• Limited liberty to the user
• More control
• More possibilities
36
Hirarchical Controls in code
public class SlideNavMenu : Control
{
private List<SlideNavMenuItem> m_MenuItems = new List<SlideNavMenuItem>();
protected override void OnPreRender(EventArgs e)
{
for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i] is SlideNavMenuItem)
{
this.m_MenuItems.Add((SlideNavMenuItem)this.Controls[i]);
}
else if (this.Controls[i] is LiteralControl || this.Controls[i] is Literal)
{
// nice try or whitespaces...
}
else
{
throw new ApplicationException("Wrong inner controls.");
}
}
}
37
Demo
• Hirachical controls
• SlideNav
38
HttpHandler
• HttpHandlers have nothing to do with
controls!
• But you can use them to realize controls
that
• call dialogs
• Do not need images or other resources in
some directory…
39
HttpHandler in code
public class MembershipManagementAjaxHandler : IHttpHandler
{
public bool IsReusable{get{return true;}}
public void ProcessRequest(HttpContext context)
{
Assembly asm = Assembly.GetExecutingAssembly();
Stream stream = asm.GetManifestResourceStream(_parameter);
Image img = Image.FromStream(stream);
img.Save(context.Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Gif);
context.Response.End();
}
}
40
Demo
• HttpHandlers
• HumanInputValidator
41
What ever you can imagine
• …
42
Demo
• ExceptionVisualizer
43
Inheritance
• Whoever wants to extend your control,
should be freely able to do so.
• No matter who your target audience is or
what functionality and features that your
control provides, you will always find that
one developer who will want to extend it
for his/her own extra mile.
44
Wrap-up
• Server Control development is easy
• The possibilities are endless
• Creating a fully functional server control can take
no longer than 15 minutes
• You don’t need any “cool” application, Notepad
can be your friend too – but intellisense is nice
45
Questions and Answers
DanielF@newtelligence.net

More Related Content

PPTX
Event-Driven Systems With MongoDB
PPTX
iOS Beginners Lesson 4
PDF
menu strip - visual basic
PPTX
Javascript 2
PPT
Ken 20150306 心得分享
PDF
Monitoring und Metriken im Wunderland
 
PDF
Effective memory management
PDF
Xamarin.android memory management gotchas
Event-Driven Systems With MongoDB
iOS Beginners Lesson 4
menu strip - visual basic
Javascript 2
Ken 20150306 心得分享
Monitoring und Metriken im Wunderland
 
Effective memory management
Xamarin.android memory management gotchas

Viewers also liked (20)

PPTX
2011 - DNC: REST Wars
PPTX
2008 - TechDays PT: Building Software + Services with Volta
PPTX
2009 - DNC: Silverlight ohne UI - Nur als Cache
PPTX
2011 - Dotnet Information Day: NUGET
PPTX
2008 - Basta!: DAL DIY
PPTX
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
PPT
2005 - NRW Conf: Design, Entwicklung und Tests
PPTX
2007 - Basta!: Nach soa kommt soc
PPTX
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
PPTX
2010 - Basta!: REST mit ASP.NET MVC
PPTX
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
PPTX
2009 - Microsoft Springbreak: IIS, PHP & WCF
PPTX
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
PPTX
2009 Dotnet Information Day: More effective c#
PPTX
2009 - NRW Conf: (ASP).NET Membership
PPTX
2015 DWX - Komponenten und Konsequenzen
PPS
2006 - NRW Conf: Asynchronous asp.net
PPTX
2010 - Basta: ASP.NET Controls für Web Forms und MVC
PPTX
2008 - Afterlaunch: 10 Tipps für WCF
PPT
2006 - Basta!: Web 2.0 mit asp.net 2.0
2011 - DNC: REST Wars
2008 - TechDays PT: Building Software + Services with Volta
2009 - DNC: Silverlight ohne UI - Nur als Cache
2011 - Dotnet Information Day: NUGET
2008 - Basta!: DAL DIY
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2005 - NRW Conf: Design, Entwicklung und Tests
2007 - Basta!: Nach soa kommt soc
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
2010 - Basta!: REST mit ASP.NET MVC
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
2009 - Microsoft Springbreak: IIS, PHP & WCF
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2009 Dotnet Information Day: More effective c#
2009 - NRW Conf: (ASP).NET Membership
2015 DWX - Komponenten und Konsequenzen
2006 - NRW Conf: Asynchronous asp.net
2010 - Basta: ASP.NET Controls für Web Forms und MVC
2008 - Afterlaunch: 10 Tipps für WCF
2006 - Basta!: Web 2.0 mit asp.net 2.0
Ad

Similar to 2006 - Basta!: Advanced server controls (20)

PPTX
Yogesh kumar kushwah represent’s
PPTX
Windows Store app using XAML and C#: Enterprise Product Development
PPT
cse581_03_EventProgramming.ppt
PPT
5809566 programming concepts in vasters
PPT
Event Programming JavaScript
PPS
CS101- Introduction to Computing- Lecture 32
PPT
javascript Event Handling and introduction to event.ppt
PPTX
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
PDF
Command Query Responsibility Segregation and Event Sourcing
PDF
The fundamental problems of GUI applications and why people choose React
PDF
GR8Conf 2011: Grails Webflow
PDF
Asp.Net MVC Framework Design Pattern
PPTX
Mastering the Lightning Framework - Part 2 - JF Paradis.pptx
PPTX
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
PPTX
Fabric - Realtime stream processing framework
PPTX
DDD, CQRS, ES lessons learned
PPTX
Advanced Coded UI Testing
KEY
PyCon AU 2012 - Debugging Live Python Web Applications
PPTX
ADF and JavaScript - AMIS SIG, July 2017
Yogesh kumar kushwah represent’s
Windows Store app using XAML and C#: Enterprise Product Development
cse581_03_EventProgramming.ppt
5809566 programming concepts in vasters
Event Programming JavaScript
CS101- Introduction to Computing- Lecture 32
javascript Event Handling and introduction to event.ppt
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
Command Query Responsibility Segregation and Event Sourcing
The fundamental problems of GUI applications and why people choose React
GR8Conf 2011: Grails Webflow
Asp.Net MVC Framework Design Pattern
Mastering the Lightning Framework - Part 2 - JF Paradis.pptx
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Fabric - Realtime stream processing framework
DDD, CQRS, ES lessons learned
Advanced Coded UI Testing
PyCon AU 2012 - Debugging Live Python Web Applications
ADF and JavaScript - AMIS SIG, July 2017
Ad

More from Daniel Fisher (14)

PPTX
NRWConf, DE: Defensive programming, resilience patterns & antifragility
PPTX
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
PPTX
2015 - Basta! 2015, DE: JavaScript und build
PPTX
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
PDF
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
PPTX
2011 - DotNetFranken: ASP.NET MVC Localization
PPTX
2011 NetUG HH: ASP.NET MVC & HTML 5
PPTX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
PPTX
2010 - Basta!: IPhone Apps mit C#
PPTX
2010 Basta!: Massendaten mit ADO.NET
PPTX
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
PPTX
2009 - Basta!: Agiles requirements engineering
PPT
2008 - Basta!: Massendaten auf dem Client
PPT
2006 DDD4: Data access layers - Convenience vs. Control and Performance?
NRWConf, DE: Defensive programming, resilience patterns & antifragility
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2011 - DotNetFranken: ASP.NET MVC Localization
2011 NetUG HH: ASP.NET MVC & HTML 5
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: IPhone Apps mit C#
2010 Basta!: Massendaten mit ADO.NET
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
2009 - Basta!: Agiles requirements engineering
2008 - Basta!: Massendaten auf dem Client
2006 DDD4: Data access layers - Convenience vs. Control and Performance?

Recently uploaded (20)

PPTX
assetexplorer- product-overview - presentation
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
history of c programming in notes for students .pptx
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Autodesk AutoCAD Crack Free Download 2025
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Cost to Outsource Software Development in 2025
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
assetexplorer- product-overview - presentation
Odoo Companies in India – Driving Business Transformation.pdf
history of c programming in notes for students .pptx
CHAPTER 2 - PM Management and IT Context
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Digital Systems & Binary Numbers (comprehensive )
Why Generative AI is the Future of Content, Code & Creativity?
Reimagine Home Health with the Power of Agentic AI​
Complete Guide to Website Development in Malaysia for SMEs
Autodesk AutoCAD Crack Free Download 2025
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Designing Intelligence for the Shop Floor.pdf
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Adobe Illustrator 28.6 Crack My Vision of Vector Design
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Computer Software and OS of computer science of grade 11.pptx
Cost to Outsource Software Development in 2025
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free

2006 - Basta!: Advanced server controls

  • 1. ASP.NET 2.0 Advanced Server Controls Daniel Fisher(lennybacon) newtelligence® AG
  • 2. 2 About me • Software Engineer, newtelligence AG • Developer • Consultant • Trainer • Author for Developer Magazines • Expert & Editor for CodeZone.de • IIS, ADO.NET … • Leader of INETA UG VfL-NiederRhein • CLIP Member
  • 3. 3 The Top 10 for better Webs • 1. Creating an n-Tier Design • 2. Working with Application Settings • 3. Creating Maintainable User Interfaces • 4. Creating Common Page Code • 5. Tracking Users' Actions • 6. Notifications of Exceptions • 7. Using State Properly • 8. Handling Unexpected Errors Gracefully • 9. Assigning Roles and Securing Web Pages • 10. There was no #10 ;-)
  • 4. 4 Maintainable User Interfaces • It’s about reusability • Html mark-up • Server side code • Client side scripts
  • 5. 5 ASP.NET Server Controls • Compiled code that can be reused in any ASP.NET web application. • Classes contained in the namespace System.Web.UI.WebControls are Server Controls, developed by Microsoft. • System.Web.UI.WebControls.Textbox • (and many, many more) • Use inheritance - all server controls come from System.Web.UI.WebControls.Control
  • 6. 6 Server Controls Usage • Register Assembly, NS and TagPrefix • Use the Control <%@ Register Assembly=“MyAssembly” Namespace=“MyNamespace” TagPrefix=“MyPrefix” %> <MyPrefix:MyControl runat=“server” id=“MyControl1” />
  • 7. 7 Server Controls Pro‘s • Encapsulate logic in reusable abstractions. • Clean mechanism to divide work across a team • Market growth of 3rd party products • Allows ISPs to provide even more value to for use in personal websites.
  • 8. 8 Server Controls Con‘s • No visual way of developing server controls, generated via code.
  • 9. 9 Something new … • Java Server Faces lent concepts from ASP.NET ;-) Quelle: Birgit Hauer
  • 10. 10 Why Create Controls on your own • Once did something twice? • You need the functionality of two or more controls working in tandem, without having to write the logic in the web application. • Existing server control almost meets your needs, but only almost • None of the existing server controls meet your needs.
  • 11. 11 Lifecycle of a control Instantiate : Constructor Initialize : OnInit method and Init Event Begin Tracking View State : TrackViewState Load View State : LoadViewState method Load Postback Data : IPostBackDataHandler.LoadPostdata method Load: OnLoad method and Load event Raise Changed Events : IPostBackDataHandler.RaisePostDataChangedEvent method Raise Postback Event : IPostBackEventHandler.RaisePostBackEvent method PreRender : OnPreRender method and PreRender event Save View State : SaveViewState method Render : Render method Unload : OnUnload method and Unload event Dispose : Dispose Method
  • 12. 12 Processing • Control creation within the method CreateChildControls() • All display logic (aside from the necessary items in above step) should be done in the method OnPreRender(). • Rendering • Custom: Override Render() method and provide custom rendering logic • Composite: Combining multiple controls into one server control – Nothing to do?
  • 13. 13 Resources • Strings • Javascript • Images • HttpHandlers - later
  • 15. 15 Properties • Set variables to influence its rendering. • Almost all properties should be stored within View State?
  • 16. 16 ViewState • ViewState is used to track and restore the state values of controls that would otherwise be lost • Base64 encoded - not easily readable, but not encrypted! • What to store • Integers • Strings • Floats • Decimals • Arrays of the data types stated above
  • 17. 17 ViewState in code [Bindable(false),Category(“Appearance”), DefaultValue(“This is the default text.”), Description(“The text of the custom control.”)] public virtual string Text { get { object o = ViewState[“Text”]; if(o != null) return (string) o; else return “This is the default text.”; } set { ViewState[“Text”] = value; } }
  • 18. 18 ViewState Concepts Send Request Send Response Send Request Send Response Ping Pong on the wire?
  • 19. 19 ViewState alternatives • Query Request.Form and Request.QueryString on your own • Use local fields – most times they work fine
  • 20. 20 Server Controls - Events • Event Handling is the best way of letting users tap into the processes of your control. • Providing events like Click for when a button is clicked, or SelectedIndexChanged when a new item has been selected in a drop down list enables developers to program in a very object oriented manner.
  • 21. 21 Events in code • Custom event eventargs and handler • The On[Event] Method • Raising an Event public class MyEventArgs : EventArgs { public MyEventArgs(string prop1, string prop2) { ... } } public delegate void MyEventHandler(object sender, MyEventArgs e); public event MyEventHandler ItemChanged; protected virtual void OnItemChanged(MyEventArgs e) { if(Events != null) { MyEventHandler eh = (MyEventHandler) Events[MyItemChangedEvent]; if(eh != null) eh(this, e); } } OnItemChanged(new MyEventArgs(“prop1”, “prop2”));
  • 22. 22 Demo • Events and delegates • EventControl
  • 23. 23 The downside - Postbacks • Implement the IPostBackEventHandler • Create an event field • Create methods to relate to the event
  • 24. 24 Postbacks - Alternatives • Server side only events • AJAX • Response.Redirect( http://example.org); • <a href=“…“>link</a>
  • 25. 25 Demo • Server side only events • WaitScreen
  • 27. 27 AJAX in code var request = new Request(); function _getXmlHttp(){ /*@cc_on @*/ /*@if (@_jscript_version >= 5) var progids =["Msxml2.XMLHTTP“,"Microsoft.XMLHTTP"]; for (i in progids){ try{ return new ActiveXObject(progids[i]) } catch (e){} }@end @*/ try{ return new XMLHttpRequest(); }catch (e2){ return null; } }
  • 29. 29
  • 31. 31 Databound Controls • ObjectDataSource • SqlDataSource • … • Abstract way to access data • A lot of overhead but a standard way… • Who is your target?
  • 32. 32 Databound in code private ITemplate _itemTemplate; public ITemplate ItemTemplate{ get{return _itemTemplate;} set{_ itemTemplate=value;} } protected override void CreateChildControls(){ CreateControlHierarchy(true); } protected virtual void CreateControlHierarchy(bool dBind){ LoadFromDataSource(); foreach (object r in _dataSource){ RepeaterItem item1 = CreateItem(ListItemType.Item, dataBind, r); } } private RepeaterItem CreateItem(…) { _itemTemplate.InstantiateIn(item); Controls.Add(item); }
  • 34. 34 Hirarchical Controls • Navigations, Tabs … • ITemplate • ChildControls
  • 35. 35 Hirarchical Controls - ChildControls • Limited liberty to the user • More control • More possibilities
  • 36. 36 Hirarchical Controls in code public class SlideNavMenu : Control { private List<SlideNavMenuItem> m_MenuItems = new List<SlideNavMenuItem>(); protected override void OnPreRender(EventArgs e) { for (int i = 0; i < this.Controls.Count; i++) { if (this.Controls[i] is SlideNavMenuItem) { this.m_MenuItems.Add((SlideNavMenuItem)this.Controls[i]); } else if (this.Controls[i] is LiteralControl || this.Controls[i] is Literal) { // nice try or whitespaces... } else { throw new ApplicationException("Wrong inner controls."); } } }
  • 38. 38 HttpHandler • HttpHandlers have nothing to do with controls! • But you can use them to realize controls that • call dialogs • Do not need images or other resources in some directory…
  • 39. 39 HttpHandler in code public class MembershipManagementAjaxHandler : IHttpHandler { public bool IsReusable{get{return true;}} public void ProcessRequest(HttpContext context) { Assembly asm = Assembly.GetExecutingAssembly(); Stream stream = asm.GetManifestResourceStream(_parameter); Image img = Image.FromStream(stream); img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); context.Response.End(); } }
  • 41. 41 What ever you can imagine • …
  • 43. 43 Inheritance • Whoever wants to extend your control, should be freely able to do so. • No matter who your target audience is or what functionality and features that your control provides, you will always find that one developer who will want to extend it for his/her own extra mile.
  • 44. 44 Wrap-up • Server Control development is easy • The possibilities are endless • Creating a fully functional server control can take no longer than 15 minutes • You don’t need any “cool” application, Notepad can be your friend too – but intellisense is nice