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

  • Thread starter EGI Consulting Jobs
  • Start date
E

EGI Consulting Jobs

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
*********************
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top