Build ASP.NET usercontrol on the fly, from XML or Database

Discussion in 'ASP .Net Web Controls' started by EGI Consulting Jobs, Jun 16, 2004.

  1. I am trying to build a ASP.Net usercontrol from an XML file or from
    the database. I have a .aspx that build dynamically from codebehind.
    I am wondering if there is a way to do this same sort of thing but
    from an XML document or SQL database. Maybe pull the creation of
    TableCells, Textboxes, Validation and create global function to build
    these objects. I have run into a brick wall. Maybe someone has also
    tried to do something similar.


    *********************
    Sample: START
    *********************
    <script language="vb" runat="server">
    Sub Page_Load(Src As Object, E As EventArgs)
    ' This example just injects some plain text
    dim whatever as control

    whatever=Page.FindControl("celltwo")
    whatever.controls.Add(new LiteralControl("Surprise"))
    Page.Controls.Add(new LiteralControl("Hello<br>"))
    Page.Controls.Add(new LiteralControl("Glad to Meet You<br>"))

    ' This example injects some table rows and cells
    dim r AS new TableRow()
    dim c1 as new TableCell()
    c1.id="emailtext"

    dim c2 as new TableCell()
    c2.id="emailctrl"

    r.cells.add(c1)
    r.cells.add(c2)
    r.id="foobar"
    t1.rows.add(r)

    ' This example injects some Web Controls
    ' into the new rows
    ' find the cell
    dim myemail = new TextBox
    myemail.ID = "emailadd"
    whatever=Page.FindControl("emailtext")
    whatever.controls.Add(new LiteralControl("Email Address"))

    ' find the cell
    whatever=Page.FindControl("emailctrl")
    whatever.controls.Add(myemail)

    dim myemailvalid = new RequiredFieldValidator
    myemailvalid.ErrorMessage = "This is a required field"
    myemailvalid.ControlToValidate = "emailadd"
    whatever.Controls.Add(myemailvalid)
    End Sub
    </script>
    <html><head>
    <title>PageControlsAdd</title>
    </head>
    <body>
    <form id="f1" runat="server">
    <asp:Table id="t1" runat="server" GridLines="both"
    BorderWidth="1px">
    <asp:TableRow>
    <asp:TableCell id="cellone">Cell 1</asp:TableCell>
    <asp:TableCell id="celltwo">Cell 2</asp:TableCell>
    </asp:TableRow>
    </asp:table>
    <asp:Button id="joincrowd" text="Join The Crowd" runat="server"/>
    </form>
    </body>
    </html>
    *********************
    Sample: END
    *********************
     
    EGI Consulting Jobs, Jun 16, 2004
    #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. Kathy Burke
    Replies:
    0
    Views:
    353
    Kathy Burke
    Aug 4, 2003
  2. Vagif Abilov
    Replies:
    2
    Views:
    599
    Vagif Abilov
    Jul 7, 2004
  3. VB Programmer

    How make usercontrol visible on the fly?

    VB Programmer, Nov 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    430
    Curt_C [MVP]
    Nov 3, 2004
  4. Replies:
    1
    Views:
    467
    Bjorn Abelli
    Oct 17, 2005
  5. Brian

    Fly outmenu on the fly

    Brian, Apr 8, 2005, in forum: Javascript
    Replies:
    0
    Views:
    127
    Brian
    Apr 8, 2005
Loading...

Share This Page