We help IT Professionals succeed at work.

Methodology for Questionnaire with Dynamic Questions

EricFleet
EricFleet asked
on
1,193 Views
Last Modified: 2008-07-24
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?
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.