Changing controls after event fires.

A

Adrian Parker

At postback time, the controls are all recreated before an event fires. If
the event determines that some of the controls need to be replaced with
different controls that you can't create as invisible beforehand, how do you
go about it ? Can you force a re-run of the control creation step ?

Thanks
Adrian Parker
 
S

Steven Cheng[MSFT]

Hi Adrian,

Welcome to ASP.NET newsgroup.
As for the creating new control after a certain postback event and make it
exist in all the sequesntial post(the control can't be precreated and set
to invisible), I think this is a common problem when developing a cutsom
web server control. Since Each dynamically created control should be
created and added into sub control's colletion in Page's Init or Load event
(before page processing postback events) so that those dynamic controls
can hanle their own postback events correctly( if they have postback
events). However, if we only create them in postback event or later,
they'll surely to disappear in the later request and event won't work
correctly.

Currently, as I've done in some former posts, the formal way is to provide
a certain flag value( can be a page's class member variable or control's
member is you are developing a custom control). That flag value should be
persisted into ViewState so as to remain between postback. Then, in our
page/custom control's Init or Load event, we create those dynamic controls
depending on the flag values. And we can set this flag value in postback
event(also modify the dyanmic controls). Then, in the sequential
post/request, those dynamic controls will always be created since the flag
value is set in the viewstate.

Here is a former thread discussing on the similiar problem:

http://groups.google.com/[email protected].
gbl&rnum=1&prev=/groups%3Fq%3Dasp.net%2Bdynamic%2Bcontrol%2Bpostback%2Bsteve
n%2Bcheng%26hl%3Dzh-CN

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top