generating textboxes on the fly ASP.Net (2003)

  • Thread starter Thread starter genc_ymeri
  • Start date Start date
G

genc_ymeri

Hello over there,
I would like to generate the textboxes on the fly depending on the number of
coulmns in a returning dataset.

I tried something like this :
TextBox temp = new TextBox();
MyPage.Controls.Add(temp);
// <-- the above on failed saying I should specify [run at server] when this
is already a server comp

Another problem I see is that how can I specify where in the form they
should be displayed ??


Any tip will be very much appreciated,
Thank you in advace,

Genc Ymeri.
 
Genc,

What are you trying to achieve? There must be a better way than adding
controls on the fly.

Eliyahu
 
Add a Panel or PlaceHolder to your page and add the dynamically created
control to the panel or placeholder.

Ie. Suppose a placeholder called pl1 has already been declaratively
added to your aspx page at design time.

Then:
TextBox temp = new TextBox();
pl1.Controls.Add(temp);

And the answer to the question of adding controls at runtime is that we
do not always know at compile time what to controls to display - e.g.
we could display two buttons (Ok, Cancel) to solicit a response from
the user or a just display label depending on the error that was
encountered.

Andy.
 
I create a general datagrid that has the maximum number of columns and set the
column header text at runtime as well as the visiblity of the columns that I
use.

I put one of a few different kinds of these datagrids on one page each w/in a
panel. I then populate the dg and set the panel's visibility.

HTH

JeffP....
 
Back
Top