SlideShare una empresa de Scribd logo
1 de 28
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
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
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.
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
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
      ()
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

Más contenido relacionado

La actualidad más candente

ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
Viral Patel
 

La actualidad más candente (20)

Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server Controls
 
Standard control in asp.net
Standard control in asp.netStandard control in asp.net
Standard control in asp.net
 
Visual studio 2008 asp net
Visual studio 2008 asp netVisual studio 2008 asp net
Visual studio 2008 asp net
 
8\9 SSIS 2008R2_Training - Debugging_Package
8\9 SSIS 2008R2_Training - Debugging_Package8\9 SSIS 2008R2_Training - Debugging_Package
8\9 SSIS 2008R2_Training - Debugging_Package
 
Windows Server AppFabric
Windows Server AppFabricWindows Server AppFabric
Windows Server AppFabric
 
Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)
 
Introduction to Asp.net 3.5 using VS 2008
Introduction to Asp.net 3.5 using VS 2008Introduction to Asp.net 3.5 using VS 2008
Introduction to Asp.net 3.5 using VS 2008
 
GAE for PHP - Google Cloud SQL and Cloud Storage
GAE for PHP - Google Cloud SQL and Cloud StorageGAE for PHP - Google Cloud SQL and Cloud Storage
GAE for PHP - Google Cloud SQL and Cloud Storage
 
Presentation on asp.net controls
Presentation on asp.net controlsPresentation on asp.net controls
Presentation on asp.net controls
 
Extending Kubernetes with Operators
Extending Kubernetes with OperatorsExtending Kubernetes with Operators
Extending Kubernetes with Operators
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
Ajax and ASP.NET AJAX
Ajax and ASP.NET AJAXAjax and ASP.NET AJAX
Ajax and ASP.NET AJAX
 
Asp dot net final (2)
Asp dot net   final (2)Asp dot net   final (2)
Asp dot net final (2)
 
Asp.net html server control
Asp.net html  server controlAsp.net html  server control
Asp.net html server control
 
深入淺出RoR
深入淺出RoR深入淺出RoR
深入淺出RoR
 
4\9 SSIS 2008R2_Training - Expression and Variables
4\9 SSIS 2008R2_Training - Expression and Variables4\9 SSIS 2008R2_Training - Expression and Variables
4\9 SSIS 2008R2_Training - Expression and Variables
 
Cognos Software Development Kit
Cognos Software Development KitCognos Software Development Kit
Cognos Software Development Kit
 
Connect your SharePoint forms to external sources
Connect your SharePoint forms to external sourcesConnect your SharePoint forms to external sources
Connect your SharePoint forms to external sources
 

Destacado (6)

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

Similar a ASP.NET Lecture 6

Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
Chui-Wen Chiu
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
SPTechCon
 

Similar a ASP.NET Lecture 6 (20)

ASP.NET Lecture 4
ASP.NET Lecture 4ASP.NET Lecture 4
ASP.NET Lecture 4
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17
 
Developing Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationDeveloping Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web Application
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
 
Mvc summary
Mvc summaryMvc summary
Mvc summary
 
Parallelminds.web partdemo1
Parallelminds.web partdemo1Parallelminds.web partdemo1
Parallelminds.web partdemo1
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
 
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showThe complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
 
Asp dot net long
Asp dot net longAsp dot net long
Asp dot net long
 
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
 
Parallelminds.asp.net with sp
Parallelminds.asp.net with spParallelminds.asp.net with sp
Parallelminds.asp.net with sp
 
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
MAX 2008 - Building your 1st AIR application
MAX 2008 - Building your 1st AIR applicationMAX 2008 - Building your 1st AIR application
MAX 2008 - Building your 1st AIR application
 
Surviving UI Automation Armageddon with BELLATRIX.pptx
Surviving UI Automation Armageddon with BELLATRIX.pptxSurviving UI Automation Armageddon with BELLATRIX.pptx
Surviving UI Automation Armageddon with BELLATRIX.pptx
 

Más de Julie Iskander

Observation Lab assignment
Observation Lab assignmentObservation Lab assignment
Observation Lab assignment
Julie Iskander
 

Más de Julie Iskander (17)

HTML 5
HTML 5HTML 5
HTML 5
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Design Pattern lecture 3
Design Pattern lecture 3Design Pattern lecture 3
Design Pattern lecture 3
 
Scriptaculous
ScriptaculousScriptaculous
Scriptaculous
 
Prototype Framework
Prototype FrameworkPrototype Framework
Prototype Framework
 
Design Pattern lecture 4
Design Pattern lecture 4Design Pattern lecture 4
Design Pattern lecture 4
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 
jQuery
jQueryjQuery
jQuery
 
ASP.NET Lecture 5
ASP.NET Lecture 5ASP.NET Lecture 5
ASP.NET Lecture 5
 
ASP.NET Lecture 7
ASP.NET Lecture 7ASP.NET Lecture 7
ASP.NET Lecture 7
 
AJAX and JSON
AJAX and JSONAJAX and JSON
AJAX and JSON
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
DOM and Events
DOM and EventsDOM and Events
DOM and Events
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
HTML and CSS part 2
HTML and CSS part 2HTML and CSS part 2
HTML and CSS part 2
 
Observation Lab assignment
Observation Lab assignmentObservation Lab assignment
Observation Lab assignment
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

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
  • 7.
  • 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
  • 11.
  • 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.
  • 14.
  • 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
  • 17.
  • 18.
  • 19.
  • 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 ()
  • 22.
  • 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

Notas del editor

  1. Create a new project  ASP.NET Server Control HTMLTextWriter class  to write raw HTML, provides methods to manage style attributes and tags
  2. SimpleControl
  3. RenderControl is not overriden
  4. ControlWithPropertyControlWithExceptionHandlin
  5. ControlWithViewState
  6. LoadPostData tell ASP.NET whether a change happened and an event is required.
  7. For a custom textbox
  8. ControlWithPostBack
  9. ControlWithPostBack
  10. GreetControl