Sunday, 25 March 2012

Session Variable in asp.net

ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session. By default, ASP.NET session state is enabled for all ASP.NET applications.

Example:

Session["FirNam"] = FirstNameTextBox.Text;
Session["LasNam"] = LastNameTextBox.Text;


we can retrieve this values in any page as
 string Firstname=Session["FirNam"].Tostring();
 string Lastname=Session["LasNam"].Tostring();

No comments:

Post a Comment