Dynamic Controls

D

danielhamd

Hello,

I'm having a problem with getting dynamic controls to work the way I
want. Here a breakdown of my situation:

1. A user adds some information. This information is added as an
object to the ViewState.
2. On Page_Load event all added objects are retrieved from the
ViewState and rendered onto the page. A 'remove' button is also added
for each object which fires is wired up for a postback.
3. When a user clicks on remove, step 2 happens, then the remove
event is fired. Therefore, the object is actually removed from the
ViewState, but it still is rendered onto the page. If you refresh the
page, it will show as gone, but not until you refresh.

So does anyone have any suggestions on how I can tweak the order that
these things occur in order for it to work? I have to have the remove
buttons created in Page_Load otherwise their events will never fire,
but if the event fires, that means the button has already been created
even if it's about to be deleted.

Thanks,
Daniel
 
P

Peter Bucher [MVP]

Hello Daniel
Therefore, the object is actually removed from the
ViewState, but it still is rendered onto the page. If you refresh the
page, it will show as gone, but not until you refresh.
i guess you are set the data that should be rendered, in your Page_Load
Event, right?
therefore this is a livecycle problem

the order is something like this:

Page_Load
Button_Click
Page_PreRender

if you set the data in Page_Load, update the datalist in Button_Click,
Page_Load doesent know about
that changes.
so, you have to set the data to be rendered in the Page_PreRender
Eventhandler, then that should work.
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top