Dynamic control on aspx page, dynamic location

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)
 
C

Chris Thunell

Could you give me an example of that in vb please. I can't seem to get it
to work.
 
E

Eliyahu Goldin

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
 
E

Edward

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.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top