Friday, August 31, 2007

Firing/Invoking Multiple Javascript fuctions on body onload

Often we land up in a scenario, where we require to invoke more than 2 javascript functions on Page Load.
We can call one function straight away by calling a function on 'onload' event of body tag. 2nd function u can invoke by overriding Render event of page life cycle. You can over-ride 'Render' event as below.
protected override void Render (HtmlTextWriter writer)
{
    base.Render (writer);
    writer.Write("");
}
Note:
Developers often try to achieve the same functionality by calling javascript function as below.
    Response.Write("");
It results in an error, because "Response.Write" tries to call the function even before page load happens, hence it can't find/locate required javascript fuction in page, which results in an error.