:: Datagrid's onInit fires before the Page_init()
That is correct. What you can do instead is move everything to the OnLoad method.
:: How different is OnLoad event of a server control from its onInit event?
There is none other than timing. The problem that you could be having with your control events not firing is if you have the following code:
Button button = new Button();
Controls.Add(button);
button.Click += new EventHandler(...);
But that code is not safe. Instead, the code can be even safer if you switch two lines of code around:
Button button = new Button();
button.Click += new EventHandler(...);
Controls.Add(button);
The reason has to be that with the first one, you are adding the control to the control tree and giving it life. You are then attaching an event while it is running and the oppurtunity for that event to fire could have passed long time ago. However, in the second bunch of code, it ensures that it has the event attached before "running". That way, it is not a game of cat 'n mouse in the page life cycle.
Another problem that you could be having is that you adding your controls like this:
protected override OnLoad(EventArgs e) {
base.OnLoad(e);
// adding controls here
}
Or:
protected override OnLoad(EventArgs e) {
// adding controls here
}
Instead, the code should look something like this:
protected override OnLoad(EventArgs e) {
// adding controls here
base.OnLoad(e);
}
The explaination can be found on this page:
http://aspalliance.com/articleViewer.aspx?aId=345&pId=3
-- Justin Lovell