Avatar of Mike Eghtebas
Mike Eghtebas
Flag for United States of America

asked on 

Session Variable Question, asp c#

In a list box, after I click on First_Name, the following stores the text value (Angela in this example)  in a session variable dictionary object named settings:
    private void ListBoxTextChangedChanged(object sender, EventArgs e)
        ListBox lb = (ListBox)sender;
        string name =lb.ID;
        name = name.Substring(3);
        int index = lb.SelectedIndex;
        settings[name] = lb.Text;
        Response.Write("1. " + settings["First_Name"].ToString());
        Session["MySettings"] = settings; 

Open in new window

Soon after the click I get the following on the screen because of Response.Write(...) in these events:
2. All    //<-- All means no selection is made.
1. Angela

Please see below for Page_Load:
        if (IsPostBack)
           settings = (Dictionary<string, string>)Session["MySettings"];
           Response.Write("2. " + settings["First_Name"].ToString());
            settings = HttpContext.Current.Session["MySettings"] as Dictionary<string, string>;

Open in new window

Question: How can I change my code in Page_Load to have a print out like:
2. Angela
      //<-- why this still shows All
1. Angela
C#ASP.NET.NET Programming

Avatar of undefined
Last Comment
Mike Eghtebas

8/22/2022 - Mon