1. ASP.NET Introduction 2. Comp of .Net Framework 3.5 3. Sys.Req for VS 2008 4. ASP.NET Envrmnt Setup 5. VS2010 Ultimate Sys.Req 6. Installing VS 2010 7. VS 2012 Sys.Req 8. Installing VS Exp 2012 9. Start the VS 2008 10. Application Life Cycle 11. Page Life Cycle 12. Page Life Cycle Events 13. ASP.NET Example 14. Event Handling 15. Default Events 16. Server Side 17. Request Object 18. Response Object 19. Server Controls 20. Server Controls Properties 21. Server Controls Methods 22. HTML Server Controls 23. Client Side 24. ASP.NET Basic Controls 25. TextBox Control 26. CheckBox Controls 27. RadioButton Controls 28. ListBox Control 29. HyperLink Control 30. Image Control 31. BulletedList Control 32. ASP.NET Directives 33. Implements Directive 34. Master Type Directive 35. Page Directive 36. PreviousPage Type 37. Managing State 38. Control State 39. Cookies 40. Query Strings 41. Server-Side State 42. Session State 43. Validation Controls 44. Required FieldValidator 45. Range Validator 46. Compare Validator 47. RegularExpressionValidator 48. Custom Validator 49. Validation Summary 50. Data Source Control 51. AdRotator Control 52. Calendar Control 53. Calendar Control Example 54. Panel Control 55. Panel Control Example 56. Multi Views Control 57. MultiView & View controls 58. MultiView Control Example 59. FileUpload Control 60. FileUpload Control Eg 61. AJAX Control 62. UpdatePanel control 63. UpdateProgress Control 64. Custom Controls 65. Custom Control Eg 66. Personalization 67. Create Simple Profile 68. ADO.NET 69. ADO.NET Objects 70. DataTable 71. DataRow 72. DataColumn 73. Object Example 74. Error Handling 75. Tracing Errors 76. Debugger 77. Security 78. Authentication 79. Authorization 80. LINQ 81. LINQ Query Operators 82. LINQ Example 83. Caching 84. Data Caching 85. Output Caching 86. Object Caching 87. Web Services 88. Create Web Services Eg 89. Web & Machine.config 90. Settings Schema 91. ASP.NET Deployment 92. XCopy Deployment 93. Web Setup Project 94. ASP Interview Part 1 95. ASP Interview Part 2 96. ASP Interview Part 3 97. ASP Interview Part 4 98. ASP Interview Part 5 99. ASP Interview Part 6
Pr.Pg Next Pg

ASP.NET Managing State tutorials

  • State management means to preserve  state of a control, web page, object/data, and user in the application explicitly because all ASP.NET web applications are stateless, i.e., by default, for each page posted to the server, the state of controls is lost.

  • If we have to track the users' information between page visits and even on multiple visits of the same page, then we need to use the State management techniques provided by ASP.NET. State management is the process by which ASP.NET let the developers maintain state and page information over multiple request for the same or different pages.

  • Types of State Management:

  • There are mainly two types of state management that ASP.NET provides:

    1. Client side state management

    2. Server side state management


1 .Client side state management

  • Storing page information using client-side options doesn't use server resources.

  • These options typically have minimal security but fast server performance because the demand on server resources is modest. However, because you must send information to the client for it to be stored, there is a practical limit on how much information you can store this way.

  • The following are the client-side state management options that ASP.NET supports:

    1. View state

    2. Control state

    3. Hidden fields

    4. Cookies

    5. Query strings


View State

  • View state is the client side state management mechanism provided by ASP.NET to store user's data, i.e., sometimes the user needs to preserve data temporarily after a post back, then the view state is the preferred way for doing it. It stores data in the generated HTML using hidden field not on the server. 

  • View State provides page level state management i.e., as long as the user is on the current page, state is available and the user redirects to the next page and the current page state is lost. View State can store any type of data because it is object type but it is preferable not to store a complex type of data due to the need for serialization and deserilization on each post back.

  • View state is enabled by default for all server side controls of ASP.NET with a property EnableviewState set to true.

  • Advantages of using view state are:

    1. No Server resources required: The view state is contained in a structure within the page code.

    2. Simple implementation: View state does not require any custom programming to use. It is on by default to maintain state data on controls.

    3. Enhanced security features: The values in view state are hashed, compressed, and encoded for Unicode implementations, which provides more security than using hidden fields.


  • Disadvantages of using view state are:

    1. It can be performance overhead if we are going to store larger amount of data, because it is associated with page only.

    2. Itís stored in a hidden filed in hashed format (which I have discussed later) still it can be easily trapped.

    3. It does not have any support on mobile devices.

  • Example: Here is a simple example of using the ViewState to carry values between postbacks:

ViewStateExample.aspx.cs Code:



Following example shows the use of ASP.NET View state:

Sam Sir


using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;


public partial class ViewStateExample : System.Web.UI.Page


protected void Page_Load(object sender, EventArgs e)


if (ViewState["UserName"] != null)

lblname.Text = ViewState["UserName"].ToString();


lblname.Text = "Not set yet...";



protected void SubmitForm_Click(object sender, EventArgs e)


ViewState["UserName"] = txtname.Text;

lblname.Text = txtname.Text;






ViewStateExample.aspx.cs Code:



Following example shows the use of ASP.NET View state:

Sam Sir


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ViewStateExample.aspx.cs" Inherits="ViewStateExample" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">


<html xmlns="">

<head runat="server">

<title>cbtSAM ASP.NET View state Example</title>



<form id="form1" runat="server">


<asp:TextBox runat="server" id="txtname" />

<asp:Button runat="server" id="SubmitForm" text="Submit the name"

onclick="SubmitForm_Click" />

<br /><br />

Name retrieved from ViewState: <asp:Label runat="server" id="lblname" />






Output managing state example

  • After running the project, enter your name in the textbox and press the button. The name will be saved in the ViewState and set to the Label as well.


Pr.Pg border                                              Next Pg