Dynamic controls - Adding & Retrieving value

B

Ben Amada

I'm a little confused about in what Event should I add dynamic controls and
in what Event should I retrieve the value of a dynamic control on postback.

I've found that adding dynamic controls in the Page Load event works, and I
realize that I need to add the dynamic controls again on each postback. But
if I'm trying to retrieve the value of a dynamic control (Text property of a
TextBox for instance), should I retrieve the value in the PreRender event?
This seems to work, but I don't know if that's when I'm supposed to retrieve
the value.

Tia,
Ben
 
E

Eliyahu Goldin

Ben,

After you re-create the controls, you can access their values in any event,
even in the same Page_Load. Pick the one that suits your application logic.

Eliyahu
 
B

Ben Amada

Eliyahu said:
Ben,

After you re-create the controls, you can access their values in any
event, even in the same Page_Load. Pick the one that suits your
application logic.

Eliyahu

Hi Eliyahu,

I'm not in front of the IDE right now ... however when I was testing this
earlier, I was recreating the dynamic controls in the Page_Load event during
a postback, however, after recreating the control, I would check the value
of the control while still in the Page_Load event, and it was empty (i.e. no
value).

If I wait until the PreRender event fires, then the value of the control is
populated.

I haven't tested yet whether the value of the control is populated or not
when a Button's Click event fires, for example (which I believe occurs
between the Page_Load and PreRender events). Hopefully I'll be able to
retrieve the value in the Click event as waiting for the PreRender event to
fire seems like "waiting to the last minute".

Thanks for your reply!
Ben
 
Joined
Aug 23, 2010
Messages
2
Reaction score
0
dynamic control

Here is the solution to add dynamic control and to get its value on Postback
chetanwarade.wordpress.com/2010/08/21/asp-net-add-dynamic-control-and-retrieve-dynamic-control-value-2/
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top