Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

This example demonstrates the basics on how to store and retrieve data between pages using ASP.NET Session. As you may know there are lots of ways on how to pass information between pages and these includes the following:

*Sessions
*Querystrings
*Cross-Page Posting
*Cookies
*Form Submit
*Server.Transfer

In this example, I'm going to show the basics on how to store the information in Session and retrieve the value of Session in the next page..

C#


    protected void Button1_Click(object sender, EventArgs e)

    {

        Session["KeyName"] = "Set Value Here";

        Response.Redirect("Page2.aspx");

    }

 

    //Then on Page2.aspx

 

    //On page load you can get the value you stored in the session variable

 

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["KeyName"] != null)

        {

            //get the Session value

            string sValue = Session["KeyName"].ToString();

        }

    }


VB.NET

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

    Session("KeyName") = "Set Value Here"

    Response.Redirect("Page2.aspx")

End Sub

 

'Then on Page2.aspx

 

'On page load you can get the value you stored in the session variable

 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    If Session("KeyName") IsNot Nothing Then

        'get the Session value

        Dim sValue As String = Session("KeyName").ToString()

    End If

End Sub


For more information bout Session state management then I would suggest you to refer at the following link below:

ASP.NET Session State Overview
Technorati Tags:
Posted on Tuesday, April 14, 2009 4:14 AM ASP.NET | Back to top


Comments on this post: Using Session to pass information between pages in ASP.NET

# re: Using Session to pass information between pages in ASP.NET
Requesting Gravatar...
really too short and helps a lot thank u so mch............
Left by rajesh on Apr 25, 2012 1:26 PM

# re: Using Session to pass information between pages in ASP.NET
Requesting Gravatar...
Can u provide me link or article to the same in asp.net MVC
Left by pavan on May 14, 2012 2:22 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net