Do you know any drawback to add controls to a page on PreRender event? please don't answer 'depends on your case' I'm talking in general:-)
The PreRender
event happens after control events, so the control could not use any events.
If you for example add a Button
in Page_PreRender
, it's too late to hook up a Click
event handler for it. At postack the button would not be recreated until after the click event had already been handled (and ignored).
Yes, see this link for the ASP.NET lifecycle:
http://msdn.microsoft.com/en-us/library/ms178472.aspx
I would recommend adding controls on the Init
event as the new control would otherwise be cleared on any postbacks. This is as per https://web.archive.org/web/20210330142645/http://www.4guysfromrolla.com/articles/092904-1.aspx.
'Raised after all controls have been initialized and any skin settings have been applied. Use this event to read or initialize control properties.'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With