ASP.NET event wiring / force postback

liptonIcedTea

Well-known member
Joined
Jan 18, 2007
Messages
89
Programming Experience
1-3
Hi,

I have a page where there is a tree view on the left and a placeholder on the right. Depending on which node is selected, it loads a webcontrol into the placeholder.

The problem here is that I only know what the webcontrol to load in after the NodeChanged event is raised and that only happens after the form is re-loaded

At the moment, the webcontrol is loaded into the placeholder but the events are not wired probably. So say my webcontrol has a button, then it is going to raise any events when the button is clicked.

Is there anyway around this? I'm not really sure what is going on, I think it has something to do with the order in which ASP.NET events are raised, and somehow it is too late to wire events after the NodEChanged event has been called but not too too late to load the control itself.
 
Are you persisting this control? Dynamically added controls have to be added again in page Load for each postback with same ID (to have the postback event handled) and other properties/handlers added also again.

see for example these two articles: http://www.codeproject.com/aspnet/dynamiccontrols.asp
http://www.codeproject.com/useritems/dynamic_control_adding.asp (don't use the PreRender like here, use Load event)


It ended up being an ID issue. I guess because the sequence of loading controls is different for each scenario, relying on ASP.NET to put IDs in was causing it to do weird things.

Once I defined the IDs myself, it worked better.

Thanks.
 
Back
Top