Best way to build a form dynamically

Discussion in 'ASP .Net Building Controls' started by Codex Twin, Feb 14, 2005.

  1. Codex Twin

    Codex Twin Guest

    Hello Control Builders::

    Part of the form that I am designing has to be built dynamically. I
    ultimately want to create a set of controls that are defined somehow in the
    database as part of the form. I am mulling over the design on how to
    implement this and I do not know what the best way to do that would be.

    One idea I have considered is to write a control which uses a ControlBuilder
    class. So I have the following attributes heading my custom control,
    DynamicFormBuilder:

    [ParseChildren(false)]
    [ControlBuilder(typeof(MetaPropertyControlBuilder))]
    public class DynamicFormBuilder : WebControl, INamingContainer
    {...}

    The class called MetaPropertyControlBuilder specified in the ControlBuilder
    attribute above is a separate class that inherits from the
    System.Web.UI.ControlBuilder class.

    Following on, I need to pass in an XML representation of the child controls
    that the control will contain. For this, I would create an XML file from the
    database (by serialization I guess) that contains a definition of the
    child-controls that are to be created by this Control.

    The XML file would be something like this:

    <ControlTextBox PropDefId="1" label="Name" name="txtName" />
    <ControlTextBox PropDefId="2" label="Reference Number" name="txtRefNumber"
    />
    <ControlTextBox PropDefId="3" label="Department" name="txtDepartment" />
    <ControlDatePicker PropDefId="4" label="From" name="dateProjectFromDate" />

    The second attribute specifies ParseChildren(false) which means that the
    MetaPropertyFormCreator will read the child XML tags that we have specified,
    and then proceed to parse the XML tags and return the type that we specify
    to be associated with that tag. This is done by overriding the
    GetChildControlType() method in the DynamicFormBuilder control.

    Then from the XML, <ControlTextBox> tag would represent a textbox control
    and a <ControlDatePicker> would return the type of a DatePicker control. The
    additional attributes are properties that I would like to pass to the
    created control. Hence the name is the name I wish to pass on as the id of
    the control. And the label as the text to be used in the preceding TableCell
    of the row that the control is contained in.

    However, I am not still not sure how I would pass in the XML that is created
    from the database to the control at run time.

    Is this the way that anyone has used? Or am I barking completely up the
    wrong tree and missed out lots of essential implementation? Bear in mind
    that the above explanation is a gloss-over of creating a Control that uses
    ControlBuilder.
    I would be grateful if someone can suggest something better/easier?

    Many thanks
     
    Codex Twin, Feb 14, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Silver
    Replies:
    0
    Views:
    565
    Alan Silver
    May 30, 2006
  2. uncensored
    Replies:
    0
    Views:
    557
    uncensored
    Oct 30, 2006
  3. Replies:
    2
    Views:
    372
  4. Bart van den Burg

    Best way to build up XHTML

    Bart van den Burg, Jan 11, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    93
    Vetle Roeim
    Jan 13, 2005
  5. Replies:
    2
    Views:
    90
    Rainer Weikusat
    Jun 1, 2014
Loading...

Share This Page