0% found this document useful (0 votes)
13 views11 pages

Lecture 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views11 pages

Lecture 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ASP.

NET Course
by T. Ala’a Khalid

1
Lecture 3
ViewState in ASP.Net

2
Lecture Objectives
 Stateless nature of HTTP protocol
 How a web form is processed
 What is ViewState
 The role of ViewState in ASP.Net
 ASP.Net server controls & ViewState
 Primary difference between ASP.Net server
controls and HTML Controls

3
Stateless nature of HTTP Protocol

 Web applications work on HTTP protocol


 HTTP protocol is a stateless protocol, meaning
it does not retain state between user requests

4
How a web form is processed

 Web forms live for barely a moment. When a


request is received
 An instance of the requested web form is created
 Events processed
 Generates the HTML & posted to the client
 The web form is immediately destroyed

5
ViewState

6
The role of ViewState in ASP.Net
 Click the button now, and the value gets
incremented every time we click. So how is this
possible now?
 It is possible because, we are using the ViewState
variable “Clicks” to preserve the data between
requests
 The ViewState data travels with every request and
response between the client and the web server
 ViewState variables are used to preserve data
across page postbacks

7
ASP.Net server controls & ViewState

8
ASP.Net server controls & ViewState
 Upon clicking the button, the value gets incremented
correctly as expected
 This is possible because, TextBox1 is an asp.net server
control, that uses ViewState internally to preserve data
across postbacks
 Because web forms has very short lifetimes, ASP.Net
takes special steps to preserve the data entered in the
controls on a web form
 Data entered in controls is sent with each request and
restored to controls in Page_Init()
 The data in these controls is then available in the
Page_Load(), Button_Click(), and many more events that
occur after Page_Init() event

9
ASP.NET server controls & HTML controls
 The Primary difference is that
 ASP.NET server controls retains state
 HTML controls do not retain state across postbacks

10
ASP.NET server controls & HTML controls
 An HTML control can be converted in ASP.NET server
controls, by adding runat=“server” attribute in the HTML
source as shown below

 ViewState data is serialized into base64-encoded strings,


and is stored in Hidden input field

11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy