SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Location
    London
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with Sessions

    Hi,

    I have used sessions in PHP and found them pretty straightforward.

    I have been trying to use sessions in ASP.net but I am finding it very tricky!

    Can someone please tell me how to simply pass a variable from one page to another?

    I am using :

    Page 1

    Dim testtxt As String

    testtxt = "hello"

    Session("MySession") = testtxt


    Page 2

    Dim Testses As String

    Testses = Session("MySession")

    Response.Write(Testses)


    This does not seem to work. Can someone please point out my mistake?
    Should I be messing around with the global.asax or web.config files? I donít want to really; as I just want stand alone pages and not applications.

    Any help greatly appreciated.

    Din

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to make sure the ASP.NET pages are in an IIS Virtual Directory, in order to use the session, you really need to run the ASP.NET site as an application, thats the way its been designed.


  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Location
    London
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    It is in an IIS Virtual Directory and it is set to run as an application. It still does not run!

    Help!

    Din

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it throw an error?

  5. #5
    SitePoint Member
    Join Date
    Feb 2005
    Location
    London
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No error, It just does not pass the variable across.(I think)

    The session variable seems to work fine on the same page:

    Page 1

    Dim testtxt As String

    testtxt = "hello"

    Session("MySession") = testtxt

    label1.text = Session("MySession")


    label1 shows the variable fine.

    If i try and display the session variable on page 2 it results in a blank.

    Could it be the way i am going to page 2?

    Response.Redirect("page 2.aspx")

    Does the way you go to another page make a difference?

    Thanks for you help,

    Din

  6. #6
    SitePoint Member
    Join Date
    Feb 2005
    Location
    London
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solved,

    My coding error!!!

    I put the page 2 session in the page_load sub!!


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Label1.text = Session("MySession")

    End Sub


    I put it into:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Label1.text = Session("MySession")

    End Sub



    now it works fine.

    Thanks

    Din


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •