I have a questions and answers page when some questions gets hidden and some gets visible depending upon the predecessor answers. at the end i need all the answers. I am trying to use dictionary for this. I add answers with a key on a changed event of each control. but none of the answers are saved when i move to next section as i am hiding the previous sections.
I am trying to save it in a viewstate and add the values so that my values persists in the dictionary.. Any ideas?
Here is the code:
Dictionary<String, String> Answers;
protected void Page_Load(object sender, EventArgs e)
{
Answers = (Dictionary<String, String>)ViewState["Answers"];
ViewState["Answers"] = Answers;
}
protected void rdb_study_popul_SelectedIndexChanged(object sender, EventArgs e)
{
ViewState["StudySamplepopulation"] = rdb_study_popul.SelectedValue.ToString();
Answers.Add("StudyPopulation", ViewState["StudySamplepopulation"].ToString());
}
Right now, Answers
will be empty if I move to next section.
Any help would be greatly appreciated.
i am getting null reference error Object reference not set to an instance of an object.
Public partial class { Dictionary Answers;
protected void Page_Load(object sender, EventArgs e)
{
Answers = ( Dictionary<String, String>)ViewState["Answers"];
}
protected void rdb_studysubj_SelectedIndexChanged(object sender, EventArgs e)
{
ViewState["StudySubjectAnimal"] = rdb_studysubj.SelectedValue.ToString();
studysub_popul.Visible = true;
Answers.Add("StudySubjectAnimal", ViewState["StudySubjectAnimal"].ToString());
ViewState["Answers"] = Answers;
}
"; } }