Dynamic control on aspx page, dynamic location

Discussion in 'ASP .Net' started by Chris Thunell, Jul 21, 2004.

  1. 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
    Chris Thunell, Jul 21, 2004
    #1
    1. Advertising

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

    "Eliyahu Goldin" <> wrote in message
    news:%...
    > 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
    >
    > "Chris Thunell" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >
    > >
    > >

    >
    >
    Chris Thunell, Jul 21, 2004
    #2
    1. Advertising

  3. 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

    "Chris Thunell" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
    >
    Eliyahu Goldin, Jul 21, 2004
    #3
  4. Chris Thunell

    Edward Guest

    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.


    > Could you give me an example of that in vb please. I can't seem to get it
    > to work.
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:%...
    > > 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
    > >
    > > "Chris Thunell" <> wrote in message
    > > news:...
    > > > 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
    > > >
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Edward, Jul 21, 2004
    #4
    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. Sriram Mallajyosula

    How do I post data from aspx page to another aspx page.

    Sriram Mallajyosula, Nov 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    970
    Steve C. Orr [MVP, MCSD]
    Nov 5, 2003
  2. Marco Antonio Montalvo Durán
    Replies:
    2
    Views:
    4,094
    Matt Morris
    Jan 23, 2004
  3. John M
    Replies:
    1
    Views:
    1,129
    Kumar Reddi
    May 29, 2005
  4. =?Utf-8?B?Uk1M?=
    Replies:
    1
    Views:
    544
    =?Utf-8?B?QW5keSBMdWtzaWM=?=
    Sep 16, 2005
  5. Luke Dalessandro
    Replies:
    0
    Views:
    607
    Luke Dalessandro
    Jan 15, 2006
Loading...

Share This Page