Author: Zunnair
Download Source Code : 903_SessionVariables.zip
In this simple article you will learn to work with session variables.
Create a web application in c#
Drag two button, two labels and one textbox on the form
Then write code on form load event
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label1.Text = "Sesstion Value";
TextBox1.Text = "Devasp Session";
Button1.Text = "Store Session Value";
Button2.Text = "Get Value";
}
}
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Label1.Text = "Sesstion Value"
TextBox1.Text = "Devasp Session"
Button1.Text = "Store Session Value"
Button2.Text = "Get Value"
End If
End Sub
After that write some code on button click even
C#
protected void Button1_Click(object sender, EventArgs e)
{
Session["DevaspSession"] = TextBox1.Text;
}
protected void Button2_Click(object sender, EventArgs e)
{
Label2.Text = Session["DevaspSession"].ToString();
}
VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Session("DevaspSession") = TextBox1.Text
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
Label2.Text = Session("DevaspSession").ToString()
End Sub
This is simple code to working with sessions variables.