sbrett 0 Newbie Poster

Here's what I'm doing:

I've got a number of online forms that I'm generating dynamically based on the database (there's basically a table that contains all of the user controls that exist in a particular form).

That part works...I have a single .aspx page (forms.aspx) that has a query string. The query string identifies a particular type of form. A method gets called that takes the query string as a parameter and builds out the form.

Here's the part I'm having a hard time with:
There may be 30-50 forms, each with their own unique set of user controls. What's the best way to gather that data? I was planning on passing the page controls to a 'form_processing' class to take care of the individual processing that occurs for each type of form, but I can't access the user control properties outside of the page.

What I'm starting with:

public partial class form : System.Web.UI.Page
{
    string queryString;

    protected void Page_Load(object sender, EventArgs e)
    {
      
    }

    protected void Page_Init(object sender, EventArgs e)
    {
       queryString = Request.QueryString["formID"];
       UIBuilder builder = new UIBuilder(queryString, pnlMain);
       builder.buildDynamicUI();
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //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;
                }
                
                if (c.GetType().Name.ToLower() == "usercontrols_usradddrop_ascx")
                {
                    UserControls_usrAddDrop ucAddDrop = (UserControls_usrAddDrop)c;
                }

                //there are many more to check on
            }

            //To Do: submit data for the specific form that is being worked on   
            
        }
    }
}

This is going to get messy when I have to put in all the logic, so this is what I'd like to do:

protected void Button1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //Send all the page data to a new class for processing
            FormProcessor fp = new FormProcessor(queryString, pnlMain, this.Page);
            fp.ProcessForm();
        }
    }

This doesn't work though. Usually when something like this doesn't work for me it means that I'm taking the wrong approach. Actually since having started this post I'm thinking that I shouldn't have to go back and check every single user control to see if it's on the page, I should just be able to have a method similar to the one that builds the page--that should tell me what controls to check for...

Anyone have any other ideas/approaches on how to process these forms?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.