Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Working with SESSION variable in code behind using asp.net 2.0.

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.
 
   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Sending and getting value of query string in same page using asp.net 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net