Last post Feb 18, 2011 04:04 PM by atconway
Feb 17, 2011 08:56 AM|sbrett00|LINK
Hey everyone. I've been tasked to rebuild an online forms system that's in place at work. The current system is a .NET web site that contains a number of forms (a separate .aspx page for each) that are created manually. What I'd like to do is build the
forms dynamically from a database, but I'm not sure the best way to go about it. Here's what I've done so far:
What's the best way to handle this? Right now I've got a single page (form.aspx) that takes a query string. The query string is used to get all the controls for that particular page from the database, then a method is called that builds out the form.
That part works great. The issue I'm having is trying to save the data for a form. I'd have to do a foreach to go through all the controls in a page, check to see if the control is a usercontrol (and if so which one), then cast that control to the correct
user control in order to get the data out of it. There may be dozens of forms with hundreds of user controls. Seems like an inefficient way to do this.
//Go through all the userControls that have been built, see if they exist on the page,
//and get values for all the inputs
foreach (Control c in pnlMain.Controls)
if (c.GetType().Name.ToLower() == "usercontrols_usrcontactinformation_ascx")
UserControls_usrContactInformation uc = (UserControls_usrContactInformation)c;
Customer customer = new Customer();
customer = uc.getCustomerInfo(s);
if (c.GetType().Name.ToLower() == "usercontrols_usrprojects_ascx")
UserControls_usrProjects ucProjects = (UserControls_usrProjects)c;
List<Project> projects = new List<Project>();
projcets = ucProjects.getList();
//keep going through all the usercontrols. Some will apply to a particular form, some won't.
Should I have a separate .aspx file for each form? Does anyone have any other ideas or suggestions? I'm also having a few issues with the best way to store the responses in the database, and maybe this is what's causing the real problems for me. Right
now every single form field for every form is store in a single table. This results in a table with hundreds of columns, many of which end up being NULL because a particular form may only use a handful of those columns. What I was thinking about doing was
storing the responses in a new table that only has a column for each datatype:
Table: Responses. Columns: StringAnswer, IntAnswer, BoolAnswer, DateTime Answer, etc.
Maybe also have a 'BinaryAnswer' column...can I serialize the field data that I get from a usercontrol and store it in a binary or xml datatype? Some usercontrols may have multiple fields.
Sorry for the novel! Any input is greatly appreciated.
Feb 18, 2011 04:04 PM|atconway|LINK
It's interesting because your description made me think of a project I worked on about 6-7 years ago. There was an ASP.NET Starter 'Portal' kit that would build its page's content dynamically based on data in the database and XML files. I found the archived
project (you can download) and placed the link below; I think you could take some ideas from the open source project to add to your application:
Portal Web Site:
A more hands off approach is to use a Content Management System (CMS) like DotNetNuke, SharePoint, etc. to create skins or templates of pages and let the user fill in the content. However if you need a more controlled approach then take apart the Portal
application in the link above to get started.
Hope this helps!