My session object appears to be working although I am having trouble with the logic in my loop. All I want to do is test the object returned by key i, and determine if its type is that of another class type, i.e., Client class or Location class.
If it is, toss them into different array I have setup.
Is what I wrote correct in testing the Type of the object stored at index i in Session?
lbl_status_message will currently display, Session Count: 2 Clients: 0 Locations: 0. So it's clearly finding my variables in session but not passing the logic in the loop.
Question
AaronMT
My session object appears to be working although I am having trouble with the logic in my loop. All I want to do is test the object returned by key i, and determine if its type is that of another class type, i.e., Client class or Location class.
If it is, toss them into different array I have setup.
Is what I wrote correct in testing the Type of the object stored at index i in Session?
Any help appreciate.
protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { if(sessionTest()) { for (int i = 0; i < Session.Count; i++) { if (Session[i].GetType().Equals(typeof(Client))) { _clients.Add((Client)Session[i]); } if (Session[i].GetType().Equals(typeof(Location))) { _locations.Add((Location)Session[i]); } Session.RemoveAt(i); } lbl_status_message.Text = "Session Count: " + Session.Count.ToString() + " - " + "Clients: " + _clients.Count + " - " + "Locations: " + _locations.Count; } } } public bool sessionTest() { return Session.Count > 0 ? true : false; }lbl_status_message will currently display, Session Count: 2 Clients: 0 Locations: 0. So it's clearly finding my variables in session but not passing the logic in the loop.
Edited by AaronMTLink to comment
Share on other sites
5 answers to this question
Recommended Posts