Can someone please help me with sessionstates

Discussion in 'General Computer Support' started by Phantom_skulcave, Oct 25, 2007.

  1. Phantom_skulcave


    Oct 25, 2007
    Likes Received:
    Hi all. I'm brand new to this forum, but after googling a few programming problems I've had, I tended to find that everyone was very helpful and polite in here; two aspects that I love about people. :)

    I was hoping you could give me some wisdom with a new problem I've got and haven't managed to find the exact answer to fix it with simple searches.

    Incidentally (yes I know it's ancient), I'm using Visual Studio 2003, specifically 2003, so please, no advise that only works with 2005+.

    Simplifying my project alot, let's just say that I've got 2 aspx pages. Form1 has two buttons on it and they both open form2. Now, depending on the button I press from form1, form2 will get that button's different session variables.


    First button will contain the code:

    Dim DefaultEmail as string = "1"
    Session("DefaultEmail ") = DefaultEmail
    Button1.Attributes.Add("onclick", "'form2.aspx','')")

    The second button contains this code:

    Dim DefaultEmail as string = "2"
    Session("DefaultEmail ") = DefaultEmail
    Button1.Attributes.Add("onclick", "'form2.aspx','')")

    My form2.loadpage code is:

    Dim DefaultEmail As String = CType(Session.Item("DefaultEmail"), String)

    If DefaultEmail = "1" then
    elseif DefaultEmail = "2" then
    end if

    Hopefully that explains the setup appropriately. It seems pretty straightforward to me, but for some reason, this doesn't behave as expected. On the first button push, it transfers the correct variable, but when I press a random button next, the variable from the last session is transferred.

    I.e., if I first press button1, form2 will run DoSomething, but if I close form2 and then press button2, form2 will run the old session and run DoSomething again. Not desired. Furthermore, if I close form2 again and then click button1 again, form2 will THEN run DoSomethingElse.

    So it seems to be a step behind after the first button push. Can anyone suggestion any remedies?

    Many thanks, all.
    Phantom_skulcave, Oct 25, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.