> What you are suggesting is defining everything programmatically
and then adding the html tree structure to the rest of the html code
with a call to somecontrol.Container.Add(code).
Actually, I think this is what you are suggesting based on your OP and the
example you originally showed.
While this works fine, it means I have to recode all of the HTML
appearing in my code programmatically, which seems somewhat
impractical and could lead to hard to maintain code. What I would
rather prefer is a solution which makes use of asp:Repeater.
Basically, asp:Repeater is designed to display controls from the
result of a data set, which is what I want.
While a Repeater can do what you've said, it was designed to display
repeating (templated) data from a result set. The fact that you can add
controls is important, but not actually necessary for the use of the
repeater.
Just that as I go through
each repeater template I want to set the ID of my HTMLTextInput
html control or equivalents so that I can reference them when
I press the corresponding submit buttons.
Is there a way to achieve this, using asp:Repeater which
seems to be what the ASP.NET people designed for this
kind of task???
I think you are coming at this backwards. It seems that you are trying to
find a coding mechanism to back your way into what can be done without any
of these problems.
When you use a DataGrid, DataList and/or Repeater control, you can insert
your own controls into the template (Item template, SelectedItem template,
Header template, etc) and then you can access these controls in response to
events that happen to your control. For example, if you were to add a
textbox or label control to the EditItem template of a DataGrid. You could
then access the textbox or label in response to some DataGrid event (like
UpdateCommand) by determining which row the grid was editing (the "e"
argument of the event handler tells us this) and then do something like
this:
Dim x as TextBox = CType(e.Item.Cells.FindControl(controlName), TextBox)
I guess what I'm getting from your comments and your original sample code is
that you are trying to use the new ASP.NET controls while programming in the
old Classic ASP style. If you abandon Classic ASP completely and move to
the ASP.NET event model and the separation of code from content paradigm,
you will find that many of the corners one can code themselves into go away.