I have a web part in which i have called several protected overriden methods such as create child controls.
Looking on the net and throwugh various books OnInit should be fired first however in my case create child controls is the very first event that has been fired.
I'm guessing that my example is wrong but could anyone shed any light as to why the create child controls is being launched first?
//}
/// <summary>
/// The CreateChildControlsEvent.
/// </summary>
protected override void CreateChildControls()
{
try
{
this.Controls.Add(new LiteralControl(_strCreateChildControlsFired));
}
catch (Exception exc)
{
this.Controls.Add(new LiteralControl("Booom.....CreateChildControls()" + exc.Message));
}
}
/// <summary>
/// The OnPreRenderEvent.
/// </summary>
/// <param name="e">(EventArgs)The default Event args parameter.</param>
protected override void OnPreRender(EventArgs e)
{
try
{
this.Controls.Add(new LiteralControl(_strOnPreRenderFired));
base.OnPreRender(e);
}
catch (Exception exc)
{
this.Controls.Add(new LiteralControl("Booom.....OnPreRender()" + exc.Message));
}
}
///// <summary>
///// The RenderWebPartEvent.
///// </summary>
///// <param name="output">(HtmlTextWriter) The default object that allows you to output to the screen in HTML format.</param>
//protected override void RenderWebPart(HtmlTextWriter output)
//{
// try
// {
// this.Controls.Add(new LiteralControl(_strRenderWebPartFired));
// base.RenderWebPart(output);
// }
// catch (Exception exc)
// {
// this.Controls.Add(new LiteralControl("Booom.....RenderWebPart()" + exc.Message));
// }
//}
/// <summary>
/// The Render Evemt.
/// </summary>
/// <param name="writer">(HtmlTextWriter) The default text writer.</param>
protected override void Render(HtmlTextWriter writer)
{
try
{
this.Controls.Add(new LiteralControl(_strRenderFired));
}
catch (Exception exc)
{
this.Controls.Add(new LiteralControl("Booom.....Render()" + exc.Message));
}
}
/// <summary>
/// The OnIt Event.
/// </summary>
/// <param name="e">(EventArgs)The default Event args parameter.</param>
protected override void OnInit(EventArgs e)
{
try
{
this.Controls.Add(new LiteralControl(_strOnInitFired));
}
catch (Exception exc)
{
this.Controls.Add(new LiteralControl("Booom.....OnInit()" + exc.Message));
}
}
/// <summary>
/// The OnLoad Event.
/// </summary>
/// <param name="e">(EventArgs)The default Event args parameter.</param>
protected override void OnLoad(EventArgs e)
{
try
{
this.Controls.Add(new LiteralControl(_strOnLoadFired));
}
catch (Exception exc)
{
this.Controls.Add(new LiteralControl("Booom.....OnLoad()" + exc.Message));
}
}
Sorry i have altered the code and some of the base. calls are missing.