ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
ASP Dot Net Tutorial - Index
ASP Dot Net Tutorial - Microsofts ASP.NET
ASP Dot Net Tutorial - Begining Web Forms
ASP Dot Net Tutorial - User Controls
ASP Dot Net Tutorial - ADO .NET
ASP Dot Net Tutorial - DataBinding to WebControls
ASP Dot Net Tutorial - DataList Controls
ASP Dot Net Tutorial - DataGrid Control
ASP Dot Net Tutorial - Advance Practical Examples on DataGrid
ASP Dot Net Tutorial - Working with DataSets
ASP Dot Net Tutorial - Working with XML
ASP Dot Net Tutorial - Forms Based Authentication
ASP Dot Net Tutorial - Windows Based Authentication

Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Makeup Artist Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses


  Home > Courses, Tutorials & eBooks > ASP.NET Tutorial > Microsoft's ASP.Net

ASP.NET Tutorial - Microsoft's ASP.NET

                                                                                                               Page 4 of 6

View State

In the preceding example 3 (DisplayMessage.aspx), it is seen that when you submit a form built from ASP.NET controls, the data entered into all the form fields is preserved at the time of submission. Microsoft calls this automatic persistence of data - View State. Therefore the View State is automatically preserved by ASP.NET control.

A simple HTML form offers no benefits of View State. With the standard HTML form, no difference is noticed between the first time the form is submitted and the seventh time You have to start with active form fields every time.

It is interesting to note that View State does not apply only to the ASP.NET controls that correspond to form elements; all the standard ASP.NET controls preserve their state.

For example, you can take a standard HTML <span> tag and convert it into an ASP.NET control like this:

<span id=”myLabel” Runat=”Server”>

In the line you magically convert the <span> tag into an ASP.NET control by adding an ID attribute and Runat=”Server” attribute. Now that the <span> tag is a server side control, any text assigned to it is preserved every time a Web Form Page that contains the tag is posted back to itself. This is illustrated in the Example 4.


<Script Runat="Server">

Sub Button_Click(s As Object, e As EventArgs )

entries.innerHtml = "<hr>" & username.Value & "<p>" & comments.Value & entries.innerHTML

End Sub





<form Runat="Server">


<br><input id="username" type="text" size="30" Runat="Server">



<br><textarea id="comments" cols=60 rows=10 Runat="Server"></textarea>


<input type="submit" value="Add Comment"

OnServerClick="Button_Click" Runat="Server">

<span id="entries" Runat="Server" />





In this example the text entered into the username and comments form fields, is preserved whenever the form is submitted. The View State of the username and comments control is automatically preserved, as shown below:

All the previous entries in the guest book are preserved at the bottom of the form. These entries are stored in the <span> tag’s view state. (The <span> tag with entries ID). Every time when the form is posted the contents of the username and comments field is added to the <span> tags View State.

The contents of the username and comment fields are added to the text displayed by the <span> tag by modifying the <span> tag’s innerHTML property. Every time a new Guest Book entry is added, the following code will be executed:

Entries.innerHTML=”<hr>” & username.Value & “<p>” & comments.Value & entries.innerHTML

However, you should know as how is the View State of the <span> tag preserved?

When you look at the source of the HTML page (in Microsoft Internet Explorer, select View Source, or in Netscape Navigator, select View, Page Source), a hidden form field will be seen that looks something like this:

<input type="hidden" name="__VIEWSTATE" value="dDwyNTE2MTA0MzQ7dDw7bDxpPDE+Oz47bDx0PDtsPGk8Mz47a Tw3Pjs+O2w8dDxwPGw8aW5uZXJodG1sOz47bDxBU1AuTkVUIGlzIHZlcnkgc G93ZXJmdWxsOz4+Ozs+O3Q8cDxsPGlubmVyaHRtbDs+O2w8XDxoclw+ RGF2aWRcPHBcPkFTUC5ORVQgaXMgdmVyeSBwb3dlcmZ1bGxcPGhyXD5K b2huXDxwXD5BU1AuTkVUIGlzIEdvb2Q7Pj47Oz47Pj47Pj47Ph/jJKTgptRcqUVtA 1enqewhZ6hu" />

Well this hidden form field contains all the previous entries in the guest book.

The View State of all the controls contained in a Web Forms Page is preserved in the hidden form field named VIEWSTATE. View State is preserved only if a form is posted back to itself.

If you leave the Guestbook.aspx page and visit the Yahoo! Home page and return again, the view state of Guestbook.aspx is lost. Or, if a form is posted to another page, the view state information will be lost.



Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
© ExpertRating 2015. All Rights Reserved.