Welcome to the horror that is asp.net and working with an outside of
microsoft standard such as javaScript.
The easist way is to put your javascript into a standard *.js file and
then load that, then call the function.
Add the following to your Page_Load, on my pages ID, in the master
page, of the body tag is "MainBody". The adds the javascript file so
it is load by the client browser and then add a function to the body
onLoad.
HtmlGenericControl jsInclude = new HtmlGenericControl("script");
jsInclude.Attributes.Add("type", "text/javascript");
jsInclude.Attribues.Add("src","myJavascriptFile.js");
this.Page.Header.Controls.Add(jsIncude);
HtmlGenericControl masterPageBodyTag =
(HtmlGenericControl)Page.Master.FindControl("MainBody");
masterPageBodyTag.attributes.Add("onLoad","myjavascriptfunction();");
------------------
On other thing, if you want something different for a PostBack you
will need to add an else clause and put in
masterPageBodyTag.Attributes.Remove("onLoad").
For some reason asp.net likes to cache the onLoad so if you have the
include so that on a PostBack it is not loaded you will still have the
onLoad call sent to the client.