Nel

Nel

  • NA
  • 716
  • 1m

Problem with naming/creating Session dynamically

Mar 2 2015 1:20 PM
Hi,
I have this code for defining/naming the sessions
if(k==0)
  {
  Response.Write("02.27 k=0" + sectionList[0]);
  Session["sectionList"] = sectionList; //changed I added [0] 02.27
  //  sessions.Add((Session["sectionList"] as List<String>) + ";");  
  sessions +=(Session["sectionList"] as String) + ";";  //03.02
  Response.Write("sessions[0]"+sessions[0]);
  k = 7;
  }
  else
  {
 
  //sectionList[1]...ex.34%
  Session[String.Format("sectionList{0}", k)] = sectionList; //I added [k] 02.27 form the sectionListnumber for that matching iners in ff file
  
  sessions+=(Session[String.Format("sectionList{0}", k)] as String) + ";" ;
  Response.Write("sessions[1]" + sessions[1]);
}
k++:
where
sessions is defined as
string sessions="";
when I run it from Response.Write I get only
sessions[1] and nothing after that, as if the Session[String.Format("sectionList{0}", k)] as String is either empty or not created.
If I put sectionList[1] instead, it displays the value, so sectionList is no empty.
Does anybody have any idea to help me please, why Session[String.Format("sectionList{0}", k)] as String doesn't retrieve anything?
Thanks a lot.