I have a relatively simple 3 page Asp.NET website with a default, input, and calculation pages. A user can load the default page, click on 'input' to fill in some info and press a button to make calculations on that info. The user can than use the browser back arrow to navigate back to the default page. The default page has some session variables that the user will need.

My problem is that while the string session variables work ok, the float variables error out when the default page is first accessed. This makes little sense to me, but I must be doing something wrong.

Here's some of the code showing the opening (default) page where the Session variables are first defined, and the calculation page where the Session variables are set.

Code:
public partial class _Default : System.Web.UI.Page 
{
    protected string slname, sfname, sopproc;
    protected float pdeath, pstroke, prenal, presp, pwound, preop, pany, plstay, psstay;

    protected void Page_Load(object sender, EventArgs e)
    {
        slname = "Fudd";
        sfname = "Elmer";
        sopproc = "CABG";
        pdeath = 2.8F;
        pstroke = 1.8F;
        prenal = 3.2F;
        presp = 8.4F;
        pwound = 1.0F;
        preop = 3.2F;
        pany = 18.9F;
        plstay = 6.8F;
        psstay = 24.2F;

        slname = (string)Session["LNAM"];
        sfname = (string)Session["FNAM"];
        sopproc = (string)Session["OPPROC"];
        pdeath = (float)Session["PDEATH"];
      // ..

    }


public partial class RiskCalc : System.Web.UI.Page
{

    public double pdeath, pstroke, prenal, presp, pwound, preop, pany, plstay, psstay;

    protected void Page_Load(object sender, EventArgs e)
    {
	//.. Do calculations for pdeath, ..., etc

        //====== Set the patient session variables
        Session["LNAM"] = s1;
        Session["FNAM"] = s2;
        Session["OPPROC"] = "Isolated Coronary Artery Bypass";
        Session["PDEATH"] = (float)pdeath;
        //..
While the first three string session variables work just fine, the float variables cause the following error when the default page is first accessed:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 41: sfname = (string)Session["FNAM"];
Line 42: sopproc = (string)Session["OPPROC"];
Line 43: pdeath = (float)Session["PDEATH"]; <== here's the error
//..
Why the string variables should work and not the float variables is a mystery to me. Can anyone shed light on this puzzling state of affairs ?

Thanks