Dynamic UI from Objects in .net web forms


I have a web page that I am using to record survey answers. Currently there can be multiple types of surveys and these surveys can have one or more types of answers (Yes/No, 1-5 stars and comments). I am pulling these questions and what types of answers are expected from a Database which I already have implemented. The issue that I have run into is that I am unsure how to keep track of the results in web forms as I am more familiar with MVC. This application is older and has to use web forms.

This is the Class that I am using to store the information that I need about the questions and their corresponding answers.

    public class SurveyQuestionAnswers {
    //  Text for the question
    public string QuestionDesc { get; set; }
    //  Rating response
    public bool HasRating { get; set; }
    public int? Rating { get; set; }
    //  Yes or no response
    public bool HasYesNo { get; set; }
    public bool? YesNo { get; set; }
    //  Comment to the response
    public bool HasAnswer { get; set; }
    public string Answer { get; set; }

In the web page, I need to be able to decide what elements are generated based on what answers are required for the question. I am able to generate the UI correctly at the surface level, but I am not able to actually use the data as it is tied to another object completely. Is there any way that I can use a list of the above class type and iterate through it while using some form controls to set the data in the proper list item?

I am just not sure if web forms is built for this type of problem or if i will have to do some of this in JavaScript on the submission of the page. Thanks in advance!




You can use a placeholder on the webforms page and add controls in code-behind (based on the question type) to the placeholder with an ID based on the ID of the class that you’re using to define the questions.

Then, you read back the values, looking for the same naming scheme, and alter the way you look for responses based on the type of control.

foreach(string key in Request.Form) {
if (!key.StartsWith(“checkbox”))


Can I loop through a Collection.Request.Form?




Add a Comment