Dynamic controls

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

Stu

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
 
J

jw56578

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

js

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top