Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Tuesday, August 24, 2010

ViewState And Session example


View state is used for store data at page level,you cant access View state data to another page.
Session state is used for store data and you can access anywhere in your website.
Session state is state specific information per client basis.

Example is given below.

View State:
 protected void btnSubmit_Click(object sender, EventArgs e)  
ViewState["DataScorceName"] = datasource;
ViewState["ClientName"] = txtCustomer.Text;
//Retrieve viewstate information
txtCname.Text = ViewState["ClientName"]
Store information in Session State:
Session["EmpName"] = txtUser.Text;
//Retrieve session value in 2nd page
lblEmp.Text = Session["UserName"].ToString();

Thanks & Regards
Santosh Singh

No comments:

Post a Comment