SlideShare une entreprise Scribd logo
1  sur  62
ASP.NET 4.0
Julie Iskander
MSC. Communication and Electronics
Course Outlines
 User Controls
 Validation Controls
 State Management
User Controls
“Always DRY”
User Controls (.ascx)
 A small section of page that can
  include static HTML code, web server
  controls.
 No <html>,<head>,<body>,<form>
  tag
 Can be reused in multiple pages
 Can have properties and events
 Have same Page events, and same
  Page properties
  Session, Application,……,etc
User Control
   Step:
    1. Create a .acsx file, add your controls
    2. Write your code-behind logic
    3. On your .aspx
     a. Register the user control
     b. Add it to the design
Step 1
Step 2
Step 3
Convert from an HTML to an aspx page
Validation Controls
Validation Controls
 Validates using client-side JavaScript
  first, if valid posts back and validates
  using server-side code.
 Must be bound to an input control
 CauseValidation property of controls
 Inherits from BaseValidator Class
  (System.Web.UI.WebControls)
Validation Controls
Convert from an HTML to an aspx page
Regular Expression
Custom Validator
Custom Validator
Validation Groups
Validation Groups
Validation Group (BONUS
Question)
 What if I added a new button with no
  validation group?
 How to make sure a control is always
  validated, regardless of the validation
  group of the clicked button?
    1- The button will validate controls with no validation
    group only, if none is found the page is postback as valid

    2- Create multiple validators for the control, one for each
    validation group and one with no validation group
State Management
“The art of retaining
information between
requests”
To Windows
                    Form
                    developers, ASP.
                    NET seems like
                    continuous
                    running
                    applications!!!

A Clever ILLUSION
State Management
 Solution to stateless nature of HTTP
 To persist information between
  requests.
 Store information over the lifetime of
  the application
 Methods used
    ◦   Cross-Page Posting
    ◦   View state
    ◦   Query String
    ◦   Cookies
    ◦   Session State
ViewState
 Uses a hidden field
 Property of Page object, a dictionary
  collection of name/value pairs
 Store information for multiple postback
  within same page.
 Stores serializable objects only
ViewState Collection
   To save value
    ◦ this.ViewState[“ButtonClicked”]=1;
   To retrieve value
    ◦ int count =
      (int)this.ViewState[“ButtonClicked”];
Convert from an HTML to an aspx page
ViewState
   To use ViewState to retain member
    variables. It is recommended to
    ◦ Save values in Page.PreRender
    ◦ Retrieve values in Page.Load
 Preserves the illusions of
  continous application  cost??
 Another limitation  bound to one
  specific page
Cross-Page Posting
 To transfer information from one
  page to another using postback
  mechanism
 Can lead you to create pages that
  are tightly coupled to one another
  and difficult to enhance and debug.
 The page will be posted with all
  control values, even the hidden
  viewstate values.
Page1                               Page2

   In an IButtonControl               Access Page1 through
    ◦ PostBackUrl Property = “url       PreviousPage Property
      of page2”




           Cross-Page Posting
Convert from an HTML to an aspx page
Query String
   Is the portion of the URL after the question mark.
   Limitations:
    ◦ Strings, which must contain URL-legal characters
      ONLY.
    ◦ Information is clearly visible .
    ◦ Can be modified by the user.
    ◦ Many browsers impose a limit on the length of a URL
      (usually from 1 to 2 KB).
   Must be placed in the URL by you, using a
    special HyperLink control, or you can use a
    Response.Redirect()
    ◦ “MyPage.aspx?ID=3”
   To retrieve the values sent use QueryString
    dictionary collection in the Request object,
    ◦ string ID = Request.QueryString["ID"];
Cookies
 Small files that are created in the web
  browser’s memory or the clients hard
  drive.
 Stores only strings.
 Accessible and readable
 Can be disabled in the browser.
 System.Net
 If no expiry date, the cookie is not
  permenant.
Cookies
   Creating cookies and storing
    information
Cookies
   Retrieving information from cookies
Convert from an HTML to an aspx page
Session State
 User-specific
 Heavyweight state management method
 Support any type of objects
 Stored in the server memory in a dictionary
  collection of name/value pair
 Instance of
  System.Web.SessionState.HttpSessionState
  class
 Adv.  never stored on client (Secure)
            global over the entire application
 Unique SessionID for each user stored
    ◦ Using Cookies
    ◦ Using modified URLs
    ◦ Only part of the session sent to the client
Session State
   Session is lost when:
    1.   Close or restart browser
    2.   Use a different browser
    3.   Timeout due to inactivity
    4.   Call Session.Abandon();
  Session.Timeout  default 20
   minutes
 Disadvantages
      Information is stored in the server memory
      Affect performance with increased usage
Convert from an HTML to an aspx page
Session State
Convert from an HTML to an aspx page
SQL Server Data Store for
SessionState
 Slowest SessionState storage
 Command to create Database Store




   Configure the web.config to use it
Application State
   Application object 
      Instance of System.Web.HttpApplicationState
       class
 Store global objects that any client can
  access, Stored in a dictionary of
  name/value pairs
 Never timeout, unless the application
  restarts
 Support any type of objects
 Retains information on the server.
Convert from an HTML to an aspx page
ASP.NET
Application and
Global Events
Application Events
   Global.asax
    ◦ event handling global events events of
      Application class.
    ◦ Can access all properties and methods of
      Application object
    ◦ No HTML or ASP.NET tags.
    ◦ ONE AND ONLY ONE for each
      application
Application Events
   PerRequest Events
    ◦ Application_BeginRequest()
    ◦ Application_EndRequest()
   PerSession Events
    ◦ Session_Start()
    ◦ Session_End()
   Special Events
    ◦ Application_Start()
    ◦ Application_End()
    ◦ Application_Error()
Convert from an HTML to an aspx page
ASP.NET
Configuration
ASP.NET Configuration
 XML-based files
 Machine level
    ◦ machine.config
      [windows]Microsoft.NetFramework[Version]C
       onfig
    ◦ Root web.config
   All applications inherit these
    configurations
ASP.NET Configuration
   Per Application
    ◦ web.config
      In root application directory
    ◦ web.config in subdirectories
ASP.NET Configuration
Reading Assignment #2
 Read ASP.NET Application Life Cycle
  Overview for IIS 7.0
  http://msdn.microsoft.com/en-
  us/library/bb470252.aspx#GlobalAsax
 Custom Validators
 Rich Controls
    ◦ Calendars
    ◦ Sitemaps
    ◦ menus
Report #2
 Show a simple example of creating
  and retrieving cookies in javascript.
 How can you load a User Control in
  code?
Lab #2
 Add validations to the registration
  form, Name(Required) and Age(between 18
  and 120) at least.
 Add site map to the site (Self Study)
 In book.aspx,
    ◦ Create a UserControl (DateTimeControl.aspx) to
      display the current date and time on the top-right
      of the page. It must be refreshed every second
      without postback.
    ◦ The checked books are added to the Shopping
      Cart when checkout is pressed the chosen books
      are displayed in a new checkout.aspx page .
    ◦ Create a user control to count number of visitors
      and add it to the footer of all pages
Lab Hints
 Add events to dynamic controls
 Cast the object sender of the event to
  the wanted control
 Use Javascript and/or jQuery for the user
  control




   Try Trace=true in Page directive, to help
    in debugging
Bonus
   In book.aspx
    ◦ When next and back is clicked the
      previously checked books must stay
      checked so as the user can know what he
      already chose.
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

Contenu connexe

Tendances

Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentRob Windsor
 
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 showSubhas Malik
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...SharePoint Saturday NY
 
ASP.NET MVC and ajax
ASP.NET MVC and ajax ASP.NET MVC and ajax
ASP.NET MVC and ajax Brij Mishra
 
Integrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio LightswitchIntegrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio LightswitchRob Windsor
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State ManagementRandy Connolly
 
Data controls ppt
Data controls pptData controls ppt
Data controls pptIblesoft
 
SharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelSharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelPhil Wicklund
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewRob Windsor
 
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 ControlsRandy Connolly
 
Creating REST Webservice With NetBeans
Creating REST Webservice With NetBeansCreating REST Webservice With NetBeans
Creating REST Webservice With NetBeansNeil Ghosh
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajaxNir Elbaz
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauSpiffy
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life CycleAbhishek Sur
 

Tendances (20)

Web controls
Web controlsWeb controls
Web controls
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
 
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
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
 
ASP.NET MVC and ajax
ASP.NET MVC and ajax ASP.NET MVC and ajax
ASP.NET MVC and ajax
 
Integrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio LightswitchIntegrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio Lightswitch
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
 
Data controls ppt
Data controls pptData controls ppt
Data controls ppt
 
SharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelSharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object Model
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development Overview
 
ASP.NET 4.0 Roadmap
ASP.NET 4.0 RoadmapASP.NET 4.0 Roadmap
ASP.NET 4.0 Roadmap
 
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
 
Ajax
AjaxAjax
Ajax
 
Creating REST Webservice With NetBeans
Creating REST Webservice With NetBeansCreating REST Webservice With NetBeans
Creating REST Webservice With NetBeans
 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshop
 
Ajax
AjaxAjax
Ajax
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Asp.net
Asp.netAsp.net
Asp.net
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
 

Similaire à ASP.NET Lecture 2

05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07Vivek chan
 
Session and state management
Session and state managementSession and state management
Session and state managementPaneliya Prince
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07Niit Care
 
Parallelminds.asp.net with sp
Parallelminds.asp.net with spParallelminds.asp.net with sp
Parallelminds.asp.net with spparallelminder
 
13 asp.net session19
13 asp.net session1913 asp.net session19
13 asp.net session19Vivek chan
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3Neeraj Mathur
 
State management
State managementState management
State managementteach4uin
 
Generating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesGenerating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesDeeptiJava
 
State management
State managementState management
State managementIblesoft
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NETPeter Gfader
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET PresentationRasel Khan
 

Similaire à ASP.NET Lecture 2 (20)

ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
 
Session and state management
Session and state managementSession and state management
Session and state management
 
Ch05 state management
Ch05 state managementCh05 state management
Ch05 state management
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
Asp.net control
Asp.net controlAsp.net control
Asp.net control
 
ASP.NET Lecture 6
ASP.NET Lecture 6ASP.NET Lecture 6
ASP.NET Lecture 6
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
 
Chapter 8 part1
Chapter 8   part1Chapter 8   part1
Chapter 8 part1
 
Parallelminds.asp.net with sp
Parallelminds.asp.net with spParallelminds.asp.net with sp
Parallelminds.asp.net with sp
 
13 asp.net session19
13 asp.net session1913 asp.net session19
13 asp.net session19
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
 
State management
State managementState management
State management
 
Generating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesGenerating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status Codes
 
State management
State managementState management
State management
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
ASP.NET Lecture 3
ASP.NET Lecture 3ASP.NET Lecture 3
ASP.NET Lecture 3
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET Presentation
 
Migration from ASP to ASP.NET
Migration from ASP to ASP.NETMigration from ASP to ASP.NET
Migration from ASP to ASP.NET
 

Plus de Julie Iskander

Plus de Julie Iskander (20)

HTML 5
HTML 5HTML 5
HTML 5
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
 
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
 
Ajax and ASP.NET AJAX
Ajax and ASP.NET AJAXAjax and ASP.NET AJAX
Ajax and ASP.NET AJAX
 
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 3
HTML and CSS part 3HTML and CSS part 3
HTML and CSS part 3
 
HTML and CSS part 2
HTML and CSS part 2HTML and CSS part 2
HTML and CSS part 2
 
Connect and combine
Connect and combineConnect and combine
Connect and combine
 

Dernier

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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 WorkerThousandEyes
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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.pdfsudhanshuwaghmare1
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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 FMESafe Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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 Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
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, Adobeapidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Dernier (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+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...
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

ASP.NET Lecture 2

  • 1. ASP.NET 4.0 Julie Iskander MSC. Communication and Electronics
  • 2. Course Outlines  User Controls  Validation Controls  State Management
  • 4. User Controls (.ascx)  A small section of page that can include static HTML code, web server controls.  No <html>,<head>,<body>,<form> tag  Can be reused in multiple pages  Can have properties and events  Have same Page events, and same Page properties Session, Application,……,etc
  • 5. User Control  Step: 1. Create a .acsx file, add your controls 2. Write your code-behind logic 3. On your .aspx a. Register the user control b. Add it to the design
  • 9. Convert from an HTML to an aspx page
  • 11. Validation Controls  Validates using client-side JavaScript first, if valid posts back and validates using server-side code.  Must be bound to an input control  CauseValidation property of controls  Inherits from BaseValidator Class (System.Web.UI.WebControls)
  • 13.
  • 14. Convert from an HTML to an aspx page
  • 16.
  • 21. Validation Group (BONUS Question)  What if I added a new button with no validation group?  How to make sure a control is always validated, regardless of the validation group of the clicked button? 1- The button will validate controls with no validation group only, if none is found the page is postback as valid 2- Create multiple validators for the control, one for each validation group and one with no validation group
  • 22. State Management “The art of retaining information between requests”
  • 23. To Windows Form developers, ASP. NET seems like continuous running applications!!! A Clever ILLUSION
  • 24. State Management  Solution to stateless nature of HTTP  To persist information between requests.  Store information over the lifetime of the application  Methods used ◦ Cross-Page Posting ◦ View state ◦ Query String ◦ Cookies ◦ Session State
  • 25. ViewState  Uses a hidden field  Property of Page object, a dictionary collection of name/value pairs  Store information for multiple postback within same page.  Stores serializable objects only
  • 26. ViewState Collection  To save value ◦ this.ViewState[“ButtonClicked”]=1;  To retrieve value ◦ int count = (int)this.ViewState[“ButtonClicked”];
  • 27. Convert from an HTML to an aspx page
  • 28. ViewState  To use ViewState to retain member variables. It is recommended to ◦ Save values in Page.PreRender ◦ Retrieve values in Page.Load  Preserves the illusions of continous application  cost??  Another limitation  bound to one specific page
  • 29. Cross-Page Posting  To transfer information from one page to another using postback mechanism  Can lead you to create pages that are tightly coupled to one another and difficult to enhance and debug.  The page will be posted with all control values, even the hidden viewstate values.
  • 30. Page1 Page2  In an IButtonControl  Access Page1 through ◦ PostBackUrl Property = “url PreviousPage Property of page2” Cross-Page Posting
  • 31. Convert from an HTML to an aspx page
  • 32. Query String  Is the portion of the URL after the question mark.  Limitations: ◦ Strings, which must contain URL-legal characters ONLY. ◦ Information is clearly visible . ◦ Can be modified by the user. ◦ Many browsers impose a limit on the length of a URL (usually from 1 to 2 KB).  Must be placed in the URL by you, using a special HyperLink control, or you can use a Response.Redirect() ◦ “MyPage.aspx?ID=3”  To retrieve the values sent use QueryString dictionary collection in the Request object, ◦ string ID = Request.QueryString["ID"];
  • 33. Cookies  Small files that are created in the web browser’s memory or the clients hard drive.  Stores only strings.  Accessible and readable  Can be disabled in the browser.  System.Net  If no expiry date, the cookie is not permenant.
  • 34. Cookies  Creating cookies and storing information
  • 35. Cookies  Retrieving information from cookies
  • 36. Convert from an HTML to an aspx page
  • 37. Session State  User-specific  Heavyweight state management method  Support any type of objects  Stored in the server memory in a dictionary collection of name/value pair  Instance of System.Web.SessionState.HttpSessionState class  Adv.  never stored on client (Secure) global over the entire application  Unique SessionID for each user stored ◦ Using Cookies ◦ Using modified URLs ◦ Only part of the session sent to the client
  • 38. Session State  Session is lost when: 1. Close or restart browser 2. Use a different browser 3. Timeout due to inactivity 4. Call Session.Abandon();  Session.Timeout  default 20 minutes  Disadvantages  Information is stored in the server memory  Affect performance with increased usage
  • 39. Convert from an HTML to an aspx page
  • 41. Convert from an HTML to an aspx page
  • 42. SQL Server Data Store for SessionState  Slowest SessionState storage  Command to create Database Store  Configure the web.config to use it
  • 43. Application State  Application object   Instance of System.Web.HttpApplicationState class  Store global objects that any client can access, Stored in a dictionary of name/value pairs  Never timeout, unless the application restarts  Support any type of objects  Retains information on the server.
  • 44. Convert from an HTML to an aspx page
  • 45.
  • 46.
  • 48. Application Events  Global.asax ◦ event handling global events events of Application class. ◦ Can access all properties and methods of Application object ◦ No HTML or ASP.NET tags. ◦ ONE AND ONLY ONE for each application
  • 49.
  • 50.
  • 51. Application Events  PerRequest Events ◦ Application_BeginRequest() ◦ Application_EndRequest()  PerSession Events ◦ Session_Start() ◦ Session_End()  Special Events ◦ Application_Start() ◦ Application_End() ◦ Application_Error()
  • 52. Convert from an HTML to an aspx page
  • 54. ASP.NET Configuration  XML-based files  Machine level ◦ machine.config  [windows]Microsoft.NetFramework[Version]C onfig ◦ Root web.config  All applications inherit these configurations
  • 55. ASP.NET Configuration  Per Application ◦ web.config  In root application directory ◦ web.config in subdirectories
  • 57. Reading Assignment #2  Read ASP.NET Application Life Cycle Overview for IIS 7.0 http://msdn.microsoft.com/en- us/library/bb470252.aspx#GlobalAsax  Custom Validators  Rich Controls ◦ Calendars ◦ Sitemaps ◦ menus
  • 58. Report #2  Show a simple example of creating and retrieving cookies in javascript.  How can you load a User Control in code?
  • 59. Lab #2  Add validations to the registration form, Name(Required) and Age(between 18 and 120) at least.  Add site map to the site (Self Study)  In book.aspx, ◦ Create a UserControl (DateTimeControl.aspx) to display the current date and time on the top-right of the page. It must be refreshed every second without postback. ◦ The checked books are added to the Shopping Cart when checkout is pressed the chosen books are displayed in a new checkout.aspx page . ◦ Create a user control to count number of visitors and add it to the footer of all pages
  • 60. Lab Hints  Add events to dynamic controls  Cast the object sender of the event to the wanted control  Use Javascript and/or jQuery for the user control  Try Trace=true in Page directive, to help in debugging
  • 61. Bonus  In book.aspx ◦ When next and back is clicked the previously checked books must stay checked so as the user can know what he already chose.
  • 62. 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

Notes de l'éditeur

  1. Standardize repeated content across all pages, reuse header, footer and navigation controls
  2. TestControl pageTryUserControl pageDateTimeControl
  3. Validation page
  4. CounterNoViewState pageCounterViewState page
  5. Deserialization happens before Page.LoadCost  enlarged page size, slower transmission times!!
  6. CrossPagePosting pageCrossPagePosting2 page
  7. Cookie page
  8. SessionID (unique 120-bit identifier)Everytime you make a request you get a new sessionID. It is not saved until you store some information in the session collection.(slight performance enhancement)Common usage in shopping cartsUsing Cookies a cookie named ASP.NET_SessionIdUsing Modified URL for clients that don’t support cookies, session ID inserted in URLhttp://localhost/lect2/(S(bn3gnc55vu3sqffghdf))/Cookieless.aspx
  9. Add a logout button which cancels session using Session.Abandon()
  10. SessionState pageSessionState2 page
  11. State Provider is any class that implements IHttpSessionState interface
  12. Furniture session example
  13. acts as a static variable conceptCan be used in counting number of visitors with the global.asaxHeavy traffic can cause inaccuracy and in consistence of data, using Lock() and UnLock() can solve the problem but cause a slow down Can count number of created sessions or how many requests received
  14. ApplicationState pageCount number of times an operation is executed
  15. ASP.NET creates a pool of application objects (1 to 100 objects, acc. To system and available threads) when the application domain is first loaded and uses one to serve each request. Each request gets exclusive access to one of these objects and when the request ends, the object is reused.
  16. Global.asax page