1.
Page_Load
event is executed on the server when the page is loading first time and then on each page post back. At the end of all page events execution the page is send it back in HTML format to the web browser and then the web browser interpret and display the page to the client.
2.On the other side the
Javascript
code is designed to be executed directly on the browser;
3.In your case, you could link the Javascript dynamically with your body
onload
event by using
ClientScript.RegisterStartupScript()
like in the next example:
StringBuilder script = new StringBuilder();
script.Append("<script language=JavaScript>");
script.Append("document.body.onload=function(){alert('Test!')}</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "Pop", script.ToString());