I am currently working on a project in ASP.net where I have to handle a large number of questions stored in XML format. My first challenge was to render these questions dynamically on a web page using RadioButtonLists and a placeholder called sectionHolder.
Once the initial set of questions is displayed, I need to implement a smooth transition to the next set of questions after performing JavaScript validation. However, I encountered an issue when trying to reload the page without losing any unsaved data stored in session variables.
My initial approach involved removing all controls from the sectionHolder and adding new questions through a server callback. Unfortunately, this method did not update the page as expected, leading me to consider alternative solutions.
One option I explored was using JavaScript to refresh the page with a time delay, but this resulted in the loss of important variables stored in my session object. This prompted me to question whether storing all necessary variables in the session object was the most efficient solution, considering the potential for messy code and constant casting.
Although I could use a function to execute JavaScript code generated by ASP.net and modify the innerHTML of a div element, I prefer utilizing the existing code that generates questions dynamically using RadioButtonLists and ListItems. This method aligns with the structure of my application and allows for seamless integration with other functionalities.
Before making any decisions, I am seeking advice on whether it is essential to store all variables in the session object, generate JavaScript code manually, or explore alternative approaches to address this issue effectively.
Thank you for your help!
---EDIT---
//Below is a snippet of the code used to render questions on the page (function to be called at start and by every page reload)
protected void AddQuestions()
{
//lstsections is parsed from xml, it contains all the topics
var cal = _lstSections.ElementAt(iCurrentSection);
//limit questions to maxnumber
var iNumQuestions = (cal._lstQuestions.Count < iNumQuestionsPerPage)
? cal._lstQuestions.Count
: iNumQuestionsPerPage;
for (int a = 0; a < iNumQuestions; a++)
{
//we offset our counter to determine page
var iCurrentID = a + iCurrentQuestionStartIndex;
//q is our current question
var q = cal._lstQuestions.ElementAt(iCurrentID);
//check if we dont have too many questions on this page
var lbl = new Label() { Text = q.GetText(), ToolTip = q.GetToolTip() };
var list = new RadioButtonList()
{
ID = "RadioButtonList" + iCurrentID,
RepeatDirection = RepeatDirection.Horizontal
};
list.Attributes.Add("runat", "Server");
list.Attributes.Add("OnClick", "processText(" + (iCurrentID) + ")");
list.EnableViewState = false;
list.CssClass = "clsRadioButtonList";
sectionHolder.Controls.Add(lbl);
sectionHolder.Controls.Add(list);
foreach (var opt in q._lstOptions)
{
var item = new ListItem() { Text = opt.Text, Value = opt.Value };
list.Items.Add(item);
}
sectionHolder.Controls.Add(new LiteralControl("<br>"));
}
}