Hi,
I use Session for passing a string from one web form to another. But I want the Session name to change dynamically and I don't know how to do it.
For example, I want to have a loop where I tried like this
for (var u=7;u<=20;u++) { var lineString = '<%= String.Join(",",(Session["'u'"] as List).ToArray()) %>' ; .... }
So Session should change to Session["7"], Session["8"],....Session["20"]
Can anybody help me please how to achieve this?
Thanks
Jignesh TrivediPosted Jun 3, 2014, 11:43 PM
I think this is because of '<%=....
Are you perform this operation in view?
Try after removing this tag...
string lineString="";
for (var u=7;u<=20;u++)
{
lineString = lineString + Session[u.ToString()].Tostring() + ","
....
}
hope this will help you.
NelPosted Jun 3, 2014, 8:23 AM
Thanks, but now even though I declared lineString and u I get a message that they don't exist in the current context
Jignesh TrivediPosted Jun 3, 2014, 12:32 AM
hi,
you mean to say you have collection of session object and you want to create comma separated string?
string lineString="";
for (var u=7;u<=20;u++)
{
lineString = '<%= lineString + Session[u.ToString()].Tostring() + "," %>';
....
}
please provide more information.