Avatar of EricFleet
 asked on

Methodology for Questionnaire with Dynamic Questions

I have a general question.

I have a page that will contain a questionnaire with multiple questions. Each of these questions have different formats. Some can by multiple choice, some fill in the blank, some may contain a datagrid for filling in detail information. All of these questions will appear on the same page so the user simply has to scroll to fill each of them in. This questionnaire may be customized depending on who logs in.

When this questionnaire is complete, the data is then saved to an underlying database.

I want to design this page in such a way that I can quickly make modifications. I do not see the web page making the decision on how to lay out the question based on data in a database. My initial thought was to use a repeater control with a custom ascx for each question and using LoadTemplate to pull it into the page. The underlying database could tell the page which questions to show, but the repeater control would load the template from the ascx file.

Does this make sense? Are there other approaches that would make more sense?
.NET ProgrammingASP.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.

Actually, as I was going to proof of concept, I found that a repeater can only handle one item template. I had thought it could handle a different one for each item. Learn something new every day, I guess.

I have settled on creating a user control for each question, and adding the controls dynamically to a placeholder control. Similar to the repeater control, but a bit more coding.

The only issue with having the totally generic ascx controls is I may want some customization in some of the controls. For example, I have a conditional two-parter where I want some additional information to appear depending on the answer to the first part. This will require some JavaScript. Still pondering this...

I've only used the repeater on a few occasions, but I do recall there being only the one item template. It is, after all, meant to show data from a single data source for the most part. I shouldn't think it'll be a big deal to simply add the usercontrols to the page dynamically just by attaching them to a single placeholder control, though a bit extra coding perhaps as you said.

Regarding the generic ascx controls, I would posit that the conditional two-parter would be a different control for sure, though if it is in essence an extension of another control, I would look into containing it within another control (or inherit the simple control if that works better for the situation, though I prefer containment & delegation over inheritence whenever possible) to show the simple question functionality along with the enhanced two-part additional information, allowing you to reuse your code effectively.

As for the javascript, iirc, you can have javascript defined just in a user control such that the javascript for that control could still be contained only by the control it affects.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy