SlideShare a Scribd company logo
ASP.NET 4.0
Julie Iskander
MSC. Communication and Electronics
Lecture Outlines
   Custom Server Controls
Custom Server Controls
   Why use them?
    ◦ Complete control over rendered HTML
    ◦ Better design-time support
   More difficult then User Controls
Custom Server Control
   Inherits System.Web.UI.Control
    ◦ Provides common properties and methods
    ◦ Ex. ID, ViewState, Controls
   Sometimes inherits from
    System.Web.UI.WebControls.WebContr
    ol
    ◦ Adds more features to implement styles
    ◦ Ex. Font, ForeColor , BackColor
Creating a Completely Custom
Control
   Steps:
    1. Create a new ASP.NET Server Control
       Project
     1. Add a new class derive from Control
     2. Override Render() method
        Use HTTPTextWriter to write the wanted HTML.
    2. In your website:
     1. Add reference to the custom control assembly
        (.dll)
     2. Register assembly (.dll) in page
     3. Register assembly (.dll) in web.config
     4. Add the item to the Toolbox
     5. Use in page
Step 1
ASP.NET Lecture 6
Convert from an HTML to an aspx page
The Rendering Process
Styling custom Controls
   Better inherit WebControl
   Don’t overrride Render()
   Specify base tag of your control in
    constructor
   Add public properties
   Initialize Properties by overriding OnInit()
   Override AddAttributeToRender() to add
    the wanted attribute values
   Override RenderContent() to add the
    wanted content
ASP.NET Lecture 6
Convert from an HTML to an aspx page
View State
 To save and retrieve property values
  in the view state
 To store information of the control
  between postbacks.
ASP.NET Lecture 6
Convert from an HTML to an aspx page
Postback Data and Change
Event
 To process the data that’s posted to
  the page.
 Implement IPostBackDataHandler
    ◦ LoadPostData() called on page
      postback before any control event
      handling, to update control state
    ◦ RaisePostDataChangedEvent() to fire
      events
    ◦ The control must have a name attribute
      for postback to work
ASP.NET Lecture 6
ASP.NET Lecture 6
ASP.NET Lecture 6
Convert from an HTML to an aspx page
Triggering a PostBack
 Is supported by a JavaScript function
  named __doPostBack();
 Override AddAttributesToRender()
     Add a javascript event attribute to the tag
     The value is set using
      Page.ClientScript.GetPostBackEventReference
      ()
ASP.NET Lecture 6
Convert from an HTML to an aspx page
Controls Property
   A collection of childern controls to be
    added to the control rendered with
    RenderChild()
Convert from an HTML to an aspx page
Lab #6
   Create a custom control
    ◦ A labeled textbox with onTextChange
      event of the textbox and a Text attribute
      for the label. The data must be retained
      between postbacks.
    ◦ Use it in register.aspx
Report #6
   What is control state of a control?
REFERENCES

 [1] Beginning ASP.NET 4 In C# 2010, Matthew
  Macdonald, Apress
 [2] Web Application Architecture Principles,
  Protocols And Practices, Leon Shklar And Richard
  Rosen, Wiley
 [3] Professional AS P.NE T 4 In C# And VB, Bill
  Evjen, Scott Hanselman And Devin Rader, Wiley
 [4] Pro ASP.NET In C# 2010, Fourth
  Edition,matthew Macdonald, Adam Freeman, And
  Mario Szpuszta, Apress

More Related Content

PPT
Web controls
PPTX
ASP.NET lecture 8
PPTX
ASP.NET Lecture 2
PPT
Asp.net server controls
PPTX
ASP.NET Page Life Cycle
PPT
Appcelerator - using node.ACS (part 1)
PPTX
Automatizacion de Procesos en Modelos Tabulares
PPTX
Introduction to MongoDB
Web controls
ASP.NET lecture 8
ASP.NET Lecture 2
Asp.net server controls
ASP.NET Page Life Cycle
Appcelerator - using node.ACS (part 1)
Automatizacion de Procesos en Modelos Tabulares
Introduction to MongoDB

What's hot (20)

PDF
ASP.NET User Controls - 20090828
PPT
ASP.NET 03 - Working With Web Server Controls
PPTX
PDF
Visual studio 2008 asp net
PPT
8\9 SSIS 2008R2_Training - Debugging_Package
PPT
Windows Server AppFabric
PDF
Having Fun Building Web Applications (Day 2 slides)
PDF
Introduction to Asp.net 3.5 using VS 2008
PDF
GAE for PHP - Google Cloud SQL and Cloud Storage
PPTX
Presentation on asp.net controls
PDF
Extending Kubernetes with Operators
PPTX
Ajax and ASP.NET AJAX
PDF
Asp dot net final (2)
PPTX
Asp.net html server control
KEY
深入淺出RoR
PPT
4\9 SSIS 2008R2_Training - Expression and Variables
PPT
PPTX
Connect your SharePoint forms to external sources
ASP.NET User Controls - 20090828
ASP.NET 03 - Working With Web Server Controls
Visual studio 2008 asp net
8\9 SSIS 2008R2_Training - Debugging_Package
Windows Server AppFabric
Having Fun Building Web Applications (Day 2 slides)
Introduction to Asp.net 3.5 using VS 2008
GAE for PHP - Google Cloud SQL and Cloud Storage
Presentation on asp.net controls
Extending Kubernetes with Operators
Ajax and ASP.NET AJAX
Asp dot net final (2)
Asp.net html server control
深入淺出RoR
4\9 SSIS 2008R2_Training - Expression and Variables
Connect your SharePoint forms to external sources
Ad

Viewers also liked (6)

PPTX
HTML and CSS part 3
PPTX
Connect and combine
PPTX
ASP.NET Lecture 3
PDF
Chapter 1 (asp.net over view)
PPTX
C for Engineers
PPTX
HTML and CSS part 1
HTML and CSS part 3
Connect and combine
ASP.NET Lecture 3
Chapter 1 (asp.net over view)
C for Engineers
HTML and CSS part 1
Ad

Similar to ASP.NET Lecture 6 (20)

PPTX
ASP.NET Lecture 4
PPT
Asp.Net Ajax Component Development
PPSX
03 asp.net session04
PPSX
12 asp.net session17
PPTX
Developing Next-Gen Enterprise Web Application
PPTX
Asp PPT (.NET )
PDF
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
PPTX
React JS .NET
PPTX
Advanced SharePoint Web Part Development
PPTX
Mvc summary
PPTX
Parallelminds.web partdemo1
PPTX
ASP.NET Lecture 1
PPT
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
PPT
Asp dot net long
PPTX
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
PPTX
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
PPTX
Parallelminds.asp.net with sp
PDF
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
PPT
Asp.net mvc
PPTX
MAX 2008 - Building your 1st AIR application
ASP.NET Lecture 4
Asp.Net Ajax Component Development
03 asp.net session04
12 asp.net session17
Developing Next-Gen Enterprise Web Application
Asp PPT (.NET )
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
React JS .NET
Advanced SharePoint Web Part Development
Mvc summary
Parallelminds.web partdemo1
ASP.NET Lecture 1
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
Asp dot net long
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
Parallelminds.asp.net with sp
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Asp.net mvc
MAX 2008 - Building your 1st AIR application

More from Julie Iskander (17)

PPTX
PPTX
Data structures and algorithms
PPTX
Design Pattern lecture 3
PPTX
Scriptaculous
PPTX
Prototype Framework
PPTX
Design Pattern lecture 4
PPTX
Design Pattern lecture 2
PPTX
Design Pattern lecture 1
PPTX
PPTX
ASP.NET Lecture 5
PPTX
ASP.NET Lecture 7
PPTX
AJAX and JSON
PPTX
Object Oriented JavaScript
PPTX
DOM and Events
PPTX
Introduction to Client-Side Javascript
PPTX
HTML and CSS part 2
PPTX
Observation Lab assignment
Data structures and algorithms
Design Pattern lecture 3
Scriptaculous
Prototype Framework
Design Pattern lecture 4
Design Pattern lecture 2
Design Pattern lecture 1
ASP.NET Lecture 5
ASP.NET Lecture 7
AJAX and JSON
Object Oriented JavaScript
DOM and Events
Introduction to Client-Side Javascript
HTML and CSS part 2
Observation Lab assignment

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Machine Learning_overview_presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Spectroscopy.pptx food analysis technology
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Machine Learning_overview_presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
SOPHOS-XG Firewall Administrator PPT.pptx
MYSQL Presentation for SQL database connectivity
Spectroscopy.pptx food analysis technology
A comparative analysis of optical character recognition models for extracting...
Encapsulation_ Review paper, used for researhc scholars
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced methodologies resolving dimensionality complications for autism neur...
Assigned Numbers - 2025 - Bluetooth® Document
Mobile App Security Testing_ A Comprehensive Guide.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

ASP.NET Lecture 6

  • 1. ASP.NET 4.0 Julie Iskander MSC. Communication and Electronics
  • 2. Lecture Outlines  Custom Server Controls
  • 3. Custom Server Controls  Why use them? ◦ Complete control over rendered HTML ◦ Better design-time support  More difficult then User Controls
  • 4. Custom Server Control  Inherits System.Web.UI.Control ◦ Provides common properties and methods ◦ Ex. ID, ViewState, Controls  Sometimes inherits from System.Web.UI.WebControls.WebContr ol ◦ Adds more features to implement styles ◦ Ex. Font, ForeColor , BackColor
  • 5. Creating a Completely Custom Control  Steps: 1. Create a new ASP.NET Server Control Project 1. Add a new class derive from Control 2. Override Render() method  Use HTTPTextWriter to write the wanted HTML. 2. In your website: 1. Add reference to the custom control assembly (.dll) 2. Register assembly (.dll) in page 3. Register assembly (.dll) in web.config 4. Add the item to the Toolbox 5. Use in page
  • 8. Convert from an HTML to an aspx page
  • 10. Styling custom Controls  Better inherit WebControl  Don’t overrride Render()  Specify base tag of your control in constructor  Add public properties  Initialize Properties by overriding OnInit()  Override AddAttributeToRender() to add the wanted attribute values  Override RenderContent() to add the wanted content
  • 12. Convert from an HTML to an aspx page
  • 13. View State  To save and retrieve property values in the view state  To store information of the control between postbacks.
  • 15. Convert from an HTML to an aspx page
  • 16. Postback Data and Change Event  To process the data that’s posted to the page.  Implement IPostBackDataHandler ◦ LoadPostData() called on page postback before any control event handling, to update control state ◦ RaisePostDataChangedEvent() to fire events ◦ The control must have a name attribute for postback to work
  • 20. Convert from an HTML to an aspx page
  • 21. Triggering a PostBack  Is supported by a JavaScript function named __doPostBack();  Override AddAttributesToRender()  Add a javascript event attribute to the tag  The value is set using Page.ClientScript.GetPostBackEventReference ()
  • 23. Convert from an HTML to an aspx page
  • 24. Controls Property  A collection of childern controls to be added to the control rendered with RenderChild()
  • 25. Convert from an HTML to an aspx page
  • 26. Lab #6  Create a custom control ◦ A labeled textbox with onTextChange event of the textbox and a Text attribute for the label. The data must be retained between postbacks. ◦ Use it in register.aspx
  • 27. Report #6  What is control state of a control?
  • 28. REFERENCES  [1] Beginning ASP.NET 4 In C# 2010, Matthew Macdonald, Apress  [2] Web Application Architecture Principles, Protocols And Practices, Leon Shklar And Richard Rosen, Wiley  [3] Professional AS P.NE T 4 In C# And VB, Bill Evjen, Scott Hanselman And Devin Rader, Wiley  [4] Pro ASP.NET In C# 2010, Fourth Edition,matthew Macdonald, Adam Freeman, And Mario Szpuszta, Apress

Editor's Notes

  • #7: Create a new project  ASP.NET Server Control HTMLTextWriter class  to write raw HTML, provides methods to manage style attributes and tags
  • #9: SimpleControl
  • #10: RenderControl is not overriden
  • #13: ControlWithPropertyControlWithExceptionHandlin
  • #16: ControlWithViewState
  • #17: LoadPostData tell ASP.NET whether a change happened and an event is required.
  • #19: For a custom textbox
  • #21: ControlWithPostBack
  • #24: ControlWithPostBack
  • #26: GreetControl