Dynamic control on aspx page, dynamic location

  • Thread starter Thread starter Chris Thunell
  • Start date Start date
C

Chris Thunell

I have an aspx web form with a table that i'm sending via response.write...
in one of the cells i would like to put a dynamically created server
control. The amount of rows is variable... so i could have 10 rows /
controls. How do i create a server control that goes into the appropriate
grid cell?

Example:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Response.Write("<TABLE id='Table1' cellSpacing='1' cellPadding='1'
width='300' border='1'>")

Response.Write("<TR>")

Response.Write("<TD>Test1</TD>")

Response.Write("<TD>test 2</TD>")

Response.Write("<TD>test 3</TD>")

Response.Write("<TD>")

'insert dynamically created server checkbox control <asp:CheckBox
id='CheckBox1' runat='server'></asp:CheckBox></TD>

Response.Write("</TR>")

Response.Write("<TR>")

Response.Write("<TD>test 4</TD>")

Response.Write("<TD>test 5</TD>")

Response.Write("<TD>test 6</TD>")

Response.Write("<TD>")

'insert dynamically created dropdown server control <asp:DropDownList
id='DropDownList1' runat='server'>

'<asp:ListItem></asp:ListItem>

'<asp:ListItem Value='VA'>VA</asp:ListItem>

'<asp:ListItem Value='MD'>MD</asp:ListItem>

'<asp:ListItem Value='DC'>DC</asp:ListItem>

'</asp:DropDownList>

Response.Write("</TD>")

Response.Write(" </TR>")

Response.Write("</TABLE>")

End Sub



Any help would be greatly appreciated!
Chris Thunell
(e-mail address removed)
 
Could you give me an example of that in vb please. I can't seem to get it
to work.
 
Chris,

Response.Write emits html for the client. A server control is processed on
the server and is rendered to the client as html. Browsers don't know
anything about <asp:xxx>. You can get server control content with method
RenderControl and use HtmlTextWriter class for rendering it to clients.

Eliyahu
 
you'd better use Table class to generate the output.

Dim tbl as Table
Dim row as TableRow
Dim cell as TableCell

cell.Controls.Add ( your server control )

row.Cells.Add( cell )

tbl.Rows.Add( row )

you'll get the result you need in the client window.
 
Back
Top