locked
Issue with session value RRS feed

  • Question

  • User105364981 posted

    i have an aspx file where it is using usercontrol file.

    on the dropdown selected index changed i am calling getdetails() method. where it calls data back from database and assing to controls

    in the dropdown !=1 means which is already saved in database and now i am trying to populate the values back from the database to these controls.
    if (ddldetails.SelectedIndex != 1)
                    {
                       
                        GetDetails();
                        ((UC)ASPxNavBar1.Items[0].FindControl("ucEmployee")).FillData();
                        ((UpdatePanel)ASPxNavBar1.Items[0].FindControl("upPnlGridReq")).Update();

                    }

    The issue is that when i debug the code i am able to see values in getdetails() but when it goes to next method filldata on user control Session["CompleteList"] is null. looks like here we are assingned in a variable but in getdetails i am assigning directly is this the issue? thats why i am seeing the session as null in filldata method?


     void GetDetails()
            {
                DataTable dt = new DataTable();
                dt = blala(where we call database SP by passing params and puling data)

                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    if (dt.Rows[i]["ControlName"].ToString() == "ID")
                    {
                        Session["ID"] = dt.Rows[i]["ControlValue"];
                    }
                    else if (dt.Rows[i]["ControlName"].ToString() == "IDName")
                    {
                        Session["IDName"] = dt.Rows[i]["ControlValue"];
                    }
    }
    }


    usercontrol-
     public void FillData()
            {

                  if ((Session["CompleteList"] != null))
                {
                    var CompleteList = (List<KeyValuePair<string, string>>)Session["CompleteList"];

                    foreach (KeyValuePair<string, string> completelist in CompleteList)
                   

                        if ((txtID.Text.Trim() == string.Empty) && (completelist .Key.Contains("scWUID")))
                            txtID.Text = CompleteList.Value;

                        if ((txtEmpID.Text.Trim() == string.Empty) && (activitySearchList.Key.Contains("EmployeeID")))
                            txtEmpID.Text = CompleteList.Value;

    Thursday, May 10, 2018 7:09 PM

All replies

  • User475983607 posted

    There is no indication in the posted code where Session["CompleteList"] is populated or how it is used.  Use the Visual Studio "Find" feature to find where Session["CompleteList"] is assigned a value.  It could be it is never assigned a value or it is assigned later in the code.  This is one of the many hazards of using Session as a variable rather that a cache as intended.

    This code block is might not functioning as expected.  Session["ID"] and  Session["IDName"] will always contain the last values from the last row.

    for (int i = 0; i < dt.Rows.Count; i++)
    {
    
    	if (dt.Rows[i]["ControlName"].ToString() == "ID")
    	{
    		Session["ID"] = dt.Rows[i]["ControlValue"];
    	}
    	else if (dt.Rows[i]["ControlName"].ToString() == "IDName")
    	{
    		Session["IDName"] = dt.Rows[i]["ControlValue"];
    	}
    }

    Thursday, May 10, 2018 7:55 PM