How to use Session variables asp.net c#

30,649

you have different names. discountedOrderTotal vs discountOrderTotal

Share:
30,649
scapegoat17
Author by

scapegoat17

Updated on July 09, 2022

Comments

  • scapegoat17
    scapegoat17 almost 2 years

    I cant seem to pass my variable through to the next page. Can anyone tell me what i am doing wrong?

    var finalValue = value * sqlCouponValue;
    finalValue = Math.Round(finalValue, 2);
    Session["discountedOrderTotal"] = finalValue.ToString();
    

    where i am trying to call it again on the next page:

    e.Row.Cells[4].Text = "$" + Session["discountOrderTotal"];
    

    Does anyone have any ideas? I have never used session variables before and am not sure why it is just returning a $. Any help would be much appreciated. Thanks!

  • Dom
    Dom almost 10 years
    happens to the best of us
  • Dom
    Dom almost 10 years
    i prefer to persist a class object to a session variable, that way i can utilize strongly typed properties.
  • Randy E
    Randy E almost 10 years
    Sometimes it just takes an extra set of eyes. Make sure you're taking regular breaks, even if its just 5 minutes every 15-20 or so to refocus your eyes.