Dynamic controls

  • Thread starter Thread starter js
  • Start date Start date
J

js

I am adding a Label and a Textbox server controls to a cell in a table.
The code is in Page_Load event. In stead of getting one for each of
the controls, I am getting two for each. It seems that the event is
fired twice, because I put Response.Write() statement in there, they
are output twice. Where should I add the code to add dynamic control
ONLY ONCE? Thanks.
 
I had this when I was using the pageload event in a user control. Put your
code in the page.Prerender event to prevent this.

Have a look round for articles on asp.net page execution order - it can be
quite complicated!

Stu
 
I think a better way to do it is to always add the controls, such as in
Page_Load, but set their visibiltity depending on if you want them to
show up or not.
 
Thank you. I got it added dynamicly by moving the add control code in
a click event of a command button. This way I only add the control
when the assocaited command button is clicked. Interestingly, when I
put the code in Prerender event, the dynamic controls are also added
twice.
 
Back
Top