Cookie and Queries string, Session in C#

State management Technique is a process by which we maintain the state & page into over multiple request for the same of different page.

  1. Cookies in Asp.Net: There are Two types of cookies in Asp.Net|

    • Session Cookie/Non persistence Cookie.
    • Persistence Cookie.

    For more Detail About Cookie Click here And For Session Click here

    On the Web Form 1

    1. protected void btnclick_click (object sender,Event args e)  
    2. {  
    3.       HttpCookie M1 = new Httpcookie["userinfo"];  
    4.       M1["name"] = textbox1.text;  
    5.       M1["email"] = textbox2.text;  
    6.       Responce.cookies.Add("M1");  
    7.       Responce.redirect("webform2.aspx");  
    8. }  
    web form1

    On the Web Form 2
    1. protected void Page_Load (object sender,Event args e)  
    2. {  
    3.       HttpCookie M1 = Request.cookies["userinfo"];  
    4.       if(Cookie ! = null)  
    5.       lable1.text = M1["name"] ;  
    6.       lable2.text = M1["email"];  
     web form 2   
  2. Query String Management System

    For more Detail About Cookie Click here:
    1. On WebForm 1  
    2. {  
    3.       protected void btnclick_click (object sender,Event args e)  
    4.       Responce.Redirect ( "webform2.aspx?username+" + textbox1.text + "& useremail + " textbox2.text);  
    5. }  
    On WebForm 2
    1. protected void Page_Load (object sender,Event args e)  
    2. {  
    3.       lable1.text = Request.querystring [ "ussername"];  
    4.       lable2.text = Request.querystring [ "usseremail"];  
  3. Session State Management System:
    1. On WebForm 1  
    2. {  
    3.       protected void btnclick_click (object sender,Event args e)  
    4.       Session [ "username"] = textbox1.text;  
    5.       Session [ "useremail"] = textbox2.text;  
    6. }  
    On WebForm 2
    1. protected void Page_Load (object sender,Event args e)  
    2. {  
    3.       if ( Session["username"] ! = null)  
    4.       {  
    5.             lable1.text = Session [ "username"].ToString;  
    6.       }  
    7.   
    8.       if ( Session["useremail"] ! = null)  
    9.       {  
    10.             lable2.text = Session [ "useremail"].ToString;  
    11.       }  
  4. Application State Management System
    1. On WebForm 1  
    2. {  
    3.       protected void btnclick_click (object sender,Event args e)  
    4.       Application [ "username"] = textbox1.text;  
    5.       Application [ "useremail"] = textbox2.text;  
    6. }  
    On WebForm 2
    1. protected void Page_Load (object sender,Event args e)    
    2. {  
    3.       lable1.text = Application [ "username"].ToString();  
    4.       lable2.text = Application [ "useremail"].ToString();  
    5.   
    6. }  
  5. View State/Hidden Field Management System:

    It is used to maintain the state of controls during Page Post Back and if we save any Control value or anything in View state we can access those value through out the page whenever it require for that check.

You can on my blog_munesh

Ebook Download
View all
Learn
View all