I am creating text boxes dynamically. I want to take those text box values and store them in a session so i can then store them in a database. How can i do this?
So, the way i am storing the DYNAMICALLY created textbox values is this way.
List<Control> _controlsList;
controlsList = new List<Control>(); // object holds the controls
Now, in my function i am adding them this way. Keep in mind i have 3+ textboxes
if (i < _applicant.Fields.Count)
_applicant.AddAnswer((_controlsList[i] as TextBox).Text);
else
_application.AddAnswer((_controlsList[i] as TextBox).Text);
_sessions.ApplicationSession = ((_controlsList[i] as TextBox).Text);
// Session["TextboxValue"] = ((_controlsList[i] as TextBox).Text);
I have a session class
public class JobApplicantSession
{
// public JobApplication ApplicationSession
public string ApplicationSession
{
get {if (HttpContext.Current.Session["Application"] != null)
// return (JobApplication)HttpContext.Current.Session["Application"];
return (string)HttpContext.Current.Session["Application"];
return null; }
set{ HttpContext.Current.Session["Application"] = value; }
}
}
I can add then but when i retrieve them from another class i only get the last added textbox. I need to be able to loop through so i can add those textbox values to a database but i cant loop through an object
var value = HttpContext.Current.Session["Application"]; //will get last textbox value
Change your session class like
and add answer to list
you can loop now..