Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i am currently coding a Jquery image slider onto a page of my web application.

I have a master page that the site uses that has a body tag.

on this page i would like to use the <body onload event> but it is not practical as i already have the body tag being added by the master page. I would like to know if i create a javascript on the Asp.net page would i be able to call the javascript from the Page_Load event? if so please could you assist in showing me how.
Posted

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:
C#
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());
 
Share this answer
 
Page.ClientScript.RegisterStartupScript(this.GetType(),"UrScriptName","javascript:functionname()",false)

if u r using update panel use
ScriptManager.RegisterStartupScript(Page,this.GetType(), "UrScriptName","javascript:functionname()", false);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900