开发者

Adding controls to page on PreRender

开发者 https://www.devze.com 2022-12-24 04:26 出处:网络
Do you know any drawback to add controls to a page on PreRender e开发者_运维百科vent? please don\'t answer \'depends on your case\' I\'m talking in general:-)The PreRender event happens after control

Do you know any drawback to add controls to a page on PreRender e开发者_运维百科vent? 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.'

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号