I want to add event handlers programmatically to the server controls rather than using their predefined OnClick properties, etc. But which would be considered a better practice for defining handlers:
- Define them in
Page_Init - Define them in
Page_Load
…and why?
Everything that has to be maintained between page cycles should be declared in
Page_Init, notPage_Load.edit All the initialization, like adding event handlers, and adding controls should be added during initialization, as the state is saved between page cycles. Handling with the content of controls and the viewstate, should be done in
Load.Check also http://msdn.microsoft.com/en-us/library/ms178472.aspx.
.