Problem with Session

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • john20
    New Member
    • Jul 2008
    • 37

    #1

    Problem with Session

    Hi All,

    I am getting Session Variable's value empty.What i am doing in code is in page load method creating menu on the page and
    declaring session variable.

    code:

    Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    sScriptApps = "<script type='text/javascript'> var menuItems = [" & vbCrLf & vbTab
    
    sScriptApps = sScriptApps & "[" & """Invalid Licence""" & "," & """javascript:setURL" & "(" & "'" & "dmLicenseNotFound.aspx" & "'" & "," & "'" & "Invalid Licence" & "'" & ");""" & "]" & vbCrLf 
     
    
     sScriptApps = sScriptApps & "];" & vbCrLf 
    sScriptApps = sScriptApps & "dm_init();" & vbCrLf
    
    sScriptApps = sScriptApps & "</script>" & vbCrLf
    
     Session("LICENCE") = "1"
    
    End sub


    when i click on the menu link its load the other page and i want to retrieve the session
    value in the loaded page.But on the loaded page i am getting empty session value.

    i am using 'IFrame' control in the page load to load the page when i click on the menu.

    is this becaue of 'IFrame' or 'Menu' which i am creating.

    Thanks

    -John
    Last edited by Curtis Rutland; Sep 2 '08, 01:17 PM. Reason: Added Code Tags - Please use the # button
  • dmj07
    New Member
    • Aug 2008
    • 55

    #2
    Setting a session should be using square brackets:

    Code:
    Session["LICENCE"] = 1;

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      Originally posted by dmj07
      Setting a session should be using square brackets:

      Code:
      Session["LICENCE"] = 1;
      Not in VB.NET. VB.NET arrays use parenthesis.

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        Originally posted by insertAlias
        Not in VB.NET. VB.NET arrays use parenthesis.
        I've found this to be the case when the object hasn't been set up properly... when I say set up, in the global.asax, if you don't initialize the session variables to a value, then when you call them from your pages, they don't seem to function as you may expect.

        Consequently I usually set them all to blank, with the exception of things like the session id. For instance if at some point in my site I'm going to start holding things like shopping cart items in Session("cart") , in my global.asax file in the Session_OnStart () event, I would do Session("cart") = Nothing.

        Otherwise when the page tries to reference the Session("cart") object, IIS decides that variable doesn't exist and always passes a null reference back, even if one of your pages has specifically set Session("cart") to hold something, for instance a string or object or whatever variable type you wish to hold.

        I don't know if it's supposed to be this way, but invariably I've found it is... and that's the workaround I found for it. Maybe someone else can enlighten us as to if you're supposed to be able to create Session variables on the fly or if you're actually supposed to define and initialize them in the global.asax file.

        Comment

        Working...