Difference between Session["var"] and Session("var")

Discussion in 'ASP .Net' started by thomson, Jun 20, 2005.

  1. thomson

    thomson Guest

    Hi,
    i create a session variable in C# as follows Session["var"] ,
    but iam not able to access the variable in VB.net

    like intmode=Session("var");

    Why is that ?

    Regards

    thomson
     
    thomson, Jun 20, 2005
    #1
    1. Advertisements

  2. thomson

    thomson Guest

    iam not getting an error but while i retrieve the value somtething like
    this

    if session("module")="" then
    intmodle=50
    else
    intmodle=session("module")
    end if

    when i come to the first "if " it skips and no statement is executed

    One morething can i add querystring variable to a Server.transfer
    method
    regards

    thomson
     
    thomson, Jun 20, 2005
    #2
    1. Advertisements

  3. thomson

    Hans Kesting Guest

    It's just syntax:
    in C# you use [ ]
    in VB you use ( )

    apart from that, it's identical.

    Hans Kesting
     
    Hans Kesting, Jun 20, 2005
    #3
  4. thomson

    Patrice Guest

    Do you have a particular message or does it come "empty" ?

    If the later, it's likely you have two sessions (check SessionID). This is
    likely not a problem with the programming language but rather with how you
    lannch these two pages (you could use the same language in both to see if
    it's still shows the same problem).

    Patrice
     
    Patrice, Jun 20, 2005
    #4
  5. thomson

    Patrice Guest

    Use Response.write to see which branch is executed. Also dump the content
    and use Response.Write(Session("module")="") to see what happens.

    For now all the code you show reads the variable. How do you create it ?

    I ask this because you said previously you *create* a session variable as
    follows :
    intmode=Session("var");

    It doesn't create a session variable, it reads it.

    Patrice

    --

     
    Patrice, Jun 20, 2005
    #5
  6. thomson

    thomson Guest

    Hi,
    Actually the issue is that i do have a page with several buttons ,
    when i click a button i call a javascript to open a new window with a
    query string value.

    The new window has 3 frames before itself i retrieve the query string
    value into a session like Session["module"].

    But one of the left frame is written in VB.net where it access the
    Session Variable.

    In order to avoid a new open window , and i used Server.transfer to the
    frame page, But nothing is coming



    Regards

    thomson
     
    thomson, Jun 20, 2005
    #6
  7. Do you get any error?

    Eliyahu
     
    Eliyahu Goldin, Jun 20, 2005
    #7
  8. thomson

    thomson Guest

    Hi all

    this is what i did

    try
    {
    Server.Transfer("MainForm.aspx?module=50");
    }
    catch(Exception objEx)
    {
    Response.Write(objEx.Message);
    }

    In the MainForm.aspx

    i do have a code <%Session["module"]=Request.QueryString["module"];%>

    and an exception is raised in the code

    What could be the reason

    Regards

    thomson
     
    thomson, Jun 20, 2005
    #8
  9. thomson

    Patrice Guest

    Please avoid mixing distinct questions in the same thread...

    1) For session have you checked SessionID to see if you actually have two
    distincts sessions
    2) Server.Transfer is server side. You don't transmit parameters this way.
    Either use Response.Redirect or see :
    http://www.dotnetbips.com/displayarticle.aspx?id=79
    (parameters are exposed through properties from the source page and read
    from the destination page through Context.Handler to get access to the
    source page).

    Patrice


    --

    "thomson" <> a écrit dans le message de
    Hi all

    this is what i did

    try
    {
    Server.Transfer("MainForm.aspx?module=50");
    }
    catch(Exception objEx)
    {
    Response.Write(objEx.Message);
    }

    In the MainForm.aspx

    i do have a code <%Session["module"]=Request.QueryString["module"];%>

    and an exception is raised in the code

    What could be the reason

    Regards

    thomson
     
    Patrice, Jun 20, 2005
    #9
  10. This could be because Session("module") is null.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Ambiguity has a certain quality to it.

     
    Kevin Spencer, Jun 20, 2005
    #10
  11. There can be only 3 options.
    1. intmodle=50 is executed
    2. intmodle=session("module") is executed
    3. an exception is raised.

    What do you observe?

    Eliyahu

     
    Eliyahu Goldin, Jun 20, 2005
    #11
    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.