I need to store data from a form for recovery from the session. Below is my rough first attempt for a generalized method for textboxes:
Load Session:
Dictionary<string, string> AppInfo = (Dictionary<string,string>) Session["ApplicantionInfo"];
this.Controls.OfType<TextBox>()
.ToList<TextBox>()
.ForEach( x => x.Text = AppInfo[x.ID] );
Save Session:
Session["ApplicationInfo"] = this.Controls.OfType<TextBox>()
.ToList<TextBox>()
.ToDictionary<TextBox,string>(kvp => kvp.ID);
However, it appears that the Controls collection is not working for me. What am I doing wrong?
this.Controls.OfType<TextBox>()
yields no results at run time when I do a quick watch on it.