Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
    Single Page App
    Bootstrap
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> ASP.Net & Web Forms >> State Management in ASP.NET
State Management in ASP.NET

In this blog I elaborate about state management in asp.net.
Views: 2580     Comments: 1
by Rohit Kesharwani on 8/8/2011

State Management in ASP.NET

State management is the process by which you maintain state and page information over multiple requests for the same or different pages.

Types of State Management

There are 2 types State Management:

Client – Side State Management

This stores information on the client's computer. The techniques available to store the state information at the client end are listed down below:

a)    View State: ViewState is the mechanism that allows state values to be preserved across page postbacks. Values stored in view state will loss with the page.

Example:

ViewState ["clickCounter"] = 1;     //set value in ViewState field

       int value = (int) ViewState ["clickCounter"];   //get value from ViewState field

b)    Hidden fields: – Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed.

Example:

<input type="hidden" runat="server" id="hdnValue" /> //creating hidden field

    hdnValue.Value="admin";                   //set value in hidden field

                  string value=hdnValue.Value;            //get value from hidden field

c)     Cookies: Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.

Example

HttpCookie cookie = new HttpCookie ("user", "abc"); // create cookie with the name  
                                                      and value    

       cookie.Expires = DateTime.Now.AddHours (2);      // specifies cookie expires after  
                                                           two hours                                                                         

Response.Cookies.Add (cookie);                   // specifies cookie and its value   
    is added

       HttpCookie cook = Request.Cookies ["user"];      // retrieving cookie information

       string val = cook.Value.ToString ();             // store the value of cookie

d)    Query Strings: Query strings store values in the URL that are visible to the user.  Use query strings when you want a user to be able to e-mail or instant message state data with a URL.

Example:

 Response.Redirect ("Home.aspx?data=user&id=abc"); //sending two values through   
                                                    url in the field data and id  
                                                    respectively.                          

        string strData = Request.QueryString ["data"];    //get value from data field

        string strId = Request.QueryString ["id"];        //get value from id field

Server – Side State Management

a)    Application State: Application state is stored in memory on the server and is faster than storing and retrieving information in a database. Application state is a useful place to store small amounts of often-used data that does not change from one user to another.

Example:
      Application["noVisitors"] = 1; // set value in the field name noVisitors

         int val = (int)Application["noVisitors"]; //get value from application field

b)    Session State: ASP.NET Session state provides a place to store values that will persist across page requests.  Values stored in Session are stored on the server and will remain in memory until they are explicitly removed or until the Session expires.

Example:

Session["emailid"] = "abc@gmail.com";     // set value in the session field

string email = Session["emailid"].ToString(); // get value from the session field

 


State management
by Anurag Sharma on 8/27/2011

ASP.Net technology offers following state management techniques.

Client side State Management

  • Cookies

  • Hidden Fields

  • View State

  • Query String

Server side State Management

  • Session State

  • Application State

Report Abuse
Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Rohit KesharwaniRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2739
  
Copyright © 2014MindStick. All Rights Reserved.