Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Is it possible to create controls dynamically by applying HTML?


Message #1 by "Martin Reeve" <mbreeve@r...> on Thu, 21 Feb 2002 15:34:29
I have what I thought was going to be an easy problem to solve. I still 

believe I may have done the difficult bit, and that I am just missing 

something trivial.



I am trying to create a table which contains a column of dynamically-

created controls. I have tried using code along the following lines to 

create the table:

  foreach (row)

  {

    TableRow tr = new TableRow();

    ...

    populate non-control cells;

    ...

    TableCell = tc = new TableCell();

    tc.Controls.Add(new dynamically-created-control);

    tr.Cells.Add(tc);

    table.Rows.Add(tr);

  }



This does work. However, it's not really what I need to do. This is 

because I want to set up my table according to an XML stream (which is 

read from a database). This is similar to the requirements for a DataGrid 

control.



Rather than using C# or VB to create the table, it seems much more 

appropriate to use XSLT to derive the entire table, complete with 

controls, already written in HTML. This HTML tree is then set as a DIV 

control's inner HTML. This seems to works really well, up to a point...



How can I get my page's event handler to respond to a text changed event 

in any of my embedded controls? The problem appears to be that event 

handlers will respond only to events on controls that have been designed 

in as server controls.



I have made my embedded controls look like:

  <input id="row3"

    name="row3"

    type="text"

    onchange="__doPostBack('row3','')"

    language="javascript"

    style="border-style:None;">



This is very similar to the way that asp.net sets up ordinary, designed-

in, input controls.



Thanks in advance...



Martin Reeve

  Return to Index