SlideShare uma empresa Scribd logo
1 de 45
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

Mais conteúdo relacionado

Destaque

2011 - DNC: REST Wars
2011 - DNC: REST Wars2011 - DNC: REST Wars
2011 - DNC: REST WarsDaniel Fisher
 
2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with VoltaDaniel Fisher
 
2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als Cache2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als CacheDaniel Fisher
 
2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGETDaniel Fisher
 
2008 - Basta!: DAL DIY
2008 - Basta!: DAL DIY2008 - Basta!: DAL DIY
2008 - Basta!: DAL DIYDaniel Fisher
 
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrowDaniel Fisher
 
2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und Tests2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und TestsDaniel Fisher
 
2007 - Basta!: Nach soa kommt soc
2007 - Basta!: Nach soa kommt soc2007 - Basta!: Nach soa kommt soc
2007 - Basta!: Nach soa kommt socDaniel Fisher
 
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...
2015 TechSummit Web & Cloud - Gem, NPM, Bower, Nuget, Paket - Päckchen hier, ...Daniel Fisher
 
2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVCDaniel Fisher
 
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragilityMD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragilityDaniel Fisher
 
2009 - Microsoft Springbreak: IIS, PHP & WCF
2009 - Microsoft Springbreak: IIS, PHP & WCF2009 - Microsoft Springbreak: IIS, PHP & WCF
2009 - Microsoft Springbreak: IIS, PHP & WCFDaniel Fisher
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageabilityDaniel Fisher
 
2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#Daniel Fisher
 
2009 - NRW Conf: (ASP).NET Membership
2009 - NRW Conf: (ASP).NET Membership2009 - NRW Conf: (ASP).NET Membership
2009 - NRW Conf: (ASP).NET MembershipDaniel Fisher
 
2015 DWX - Komponenten und Konsequenzen
2015 DWX - Komponenten und Konsequenzen2015 DWX - Komponenten und Konsequenzen
2015 DWX - Komponenten und KonsequenzenDaniel Fisher
 
2006 - NRW Conf: Asynchronous asp.net
2006 - NRW Conf: Asynchronous asp.net2006 - NRW Conf: Asynchronous asp.net
2006 - NRW Conf: Asynchronous asp.netDaniel Fisher
 
2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVC2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVCDaniel Fisher
 
2008 - Afterlaunch: 10 Tipps für WCF
2008 - Afterlaunch: 10 Tipps für WCF2008 - Afterlaunch: 10 Tipps für WCF
2008 - Afterlaunch: 10 Tipps für WCFDaniel Fisher
 
2006 - Basta!: Web 2.0 mit asp.net 2.0
2006 - Basta!: Web 2.0 mit asp.net 2.02006 - Basta!: Web 2.0 mit asp.net 2.0
2006 - Basta!: Web 2.0 mit asp.net 2.0Daniel Fisher
 

Destaque (20)

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

Semelhante a 2006 - Basta!: Advanced server controls

Yogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh Kushwah
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 
cse581_03_EventProgramming.ppt
cse581_03_EventProgramming.pptcse581_03_EventProgramming.ppt
cse581_03_EventProgramming.ppttadudemise
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32Bilal Ahmed
 
javascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptjavascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptLalith86
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB
 
Command Query Responsibility Segregation and Event Sourcing
Command Query Responsibility Segregation and Event SourcingCommand Query Responsibility Segregation and Event Sourcing
Command Query Responsibility Segregation and Event SourcingMitinPavel
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactOliver N
 
GR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Patternmaddinapudi
 
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...goodfriday
 
Fabric - Realtime stream processing framework
Fabric - Realtime stream processing frameworkFabric - Realtime stream processing framework
Fabric - Realtime stream processing frameworkShashank Gautam
 
DDD, CQRS, ES lessons learned
DDD, CQRS, ES lessons learnedDDD, CQRS, ES lessons learned
DDD, CQRS, ES lessons learnedQframe
 
Advanced Coded UI Testing
Advanced Coded UI TestingAdvanced Coded UI Testing
Advanced Coded UI TestingShai Raiten
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 
ADF and JavaScript - AMIS SIG, July 2017
ADF and JavaScript - AMIS SIG, July 2017ADF and JavaScript - AMIS SIG, July 2017
ADF and JavaScript - AMIS SIG, July 2017Lucas Jellema
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Patterngoodfriday
 

Semelhante a 2006 - Basta!: Advanced server controls (20)

Yogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’s
 
Extjs
ExtjsExtjs
Extjs
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
cse581_03_EventProgramming.ppt
cse581_03_EventProgramming.pptcse581_03_EventProgramming.ppt
cse581_03_EventProgramming.ppt
 
Event Programming JavaScript
Event Programming JavaScriptEvent Programming JavaScript
Event Programming JavaScript
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
javascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptjavascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.ppt
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
 
Command Query Responsibility Segregation and Event Sourcing
Command Query Responsibility Segregation and Event SourcingCommand Query Responsibility Segregation and Event Sourcing
Command Query Responsibility Segregation and Event Sourcing
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose React
 
GR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails Webflow
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Pattern
 
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
 
Fabric - Realtime stream processing framework
Fabric - Realtime stream processing frameworkFabric - Realtime stream processing framework
Fabric - Realtime stream processing framework
 
DDD, CQRS, ES lessons learned
DDD, CQRS, ES lessons learnedDDD, CQRS, ES lessons learned
DDD, CQRS, ES lessons learned
 
Advanced Coded UI Testing
Advanced Coded UI TestingAdvanced Coded UI Testing
Advanced Coded UI Testing
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
ADF and JavaScript - AMIS SIG, July 2017
ADF and JavaScript - AMIS SIG, July 2017ADF and JavaScript - AMIS SIG, July 2017
ADF and JavaScript - AMIS SIG, July 2017
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 

Mais de Daniel Fisher

NRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragilityNRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragilityDaniel Fisher
 
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an....NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...Daniel Fisher
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und buildDaniel Fisher
 
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...Daniel Fisher
 
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...Daniel Fisher
 
2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC Localization2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC LocalizationDaniel Fisher
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5Daniel Fisher
 
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAXDaniel Fisher
 
2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#Daniel Fisher
 
2010 Basta!: Massendaten mit ADO.NET
2010 Basta!: Massendaten mit ADO.NET2010 Basta!: Massendaten mit ADO.NET
2010 Basta!: Massendaten mit ADO.NETDaniel Fisher
 
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
2009 - Basta!: Url rewriting mit iis, asp.net und routing engineDaniel Fisher
 
2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineering2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineeringDaniel Fisher
 
2008 - Basta!: Massendaten auf dem Client
2008 - Basta!: Massendaten auf dem Client2008 - Basta!: Massendaten auf dem Client
2008 - Basta!: Massendaten auf dem ClientDaniel Fisher
 
2006 DDD4: Data access layers - Convenience vs. Control and Performance?
2006 DDD4: Data access layers - Convenience vs. Control and Performance?2006 DDD4: Data access layers - Convenience vs. Control and Performance?
2006 DDD4: Data access layers - Convenience vs. Control and Performance?Daniel Fisher
 

Mais de Daniel Fisher (14)

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

Último

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Último (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

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