I have the following code:
protected void Page_Load(object sender, EventArgs e) { //get questions List<Question> questions = Question.GetQuestionsForTesting(); //for each question foreach (Question currQuestion in questions) { //display the questionAnswer control QuestionAnswer newControl = (QuestionAnswer)LoadControl("~/Account/QuestionAnswer.ascx"); newControl.newQuestion = currQuestion; questionAnswerPanel.Controls.Add(newControl); } } protected void submitAnswers_Click(object sender, EventArgs e) { //for each control foreach (QuestionAnswer questionAnswerControl in questionAnswerPanel.Controls) { //get ID of question and correct/incorrect Tuple<Boolean, int> correctIncorrectANDquestionID = questionAnswerControl.isAnswerCorrect(); //save in DB } } and
<asp:Panel runat="server" ID="questionAnswerPanel"></asp:Panel> <asp:Button runat="server" ID="submitAnswers" OnClick="submitAnswers_Click" Text="Submit Answers"/> When I click the submitAnswers button the page load gets called and then the button event. I need some way of checking the answers submitted but I am not able to do this currently as my controls disappear on the postback along with the questions and their answers. So when the event method finally gets called I am just checking answers from new questions with no user input.
I have looked at various other questions but I can't find a similar question.