Click here to Skip to main content
13,002,399 members (79,729 online)
Rate this:
Please Sign up or sign in to vote.

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 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 5-Aug-14 0:18am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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">");
ClientScript.RegisterClientScriptBlock(this.GetType(), "Pop", script.ToString());
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 5 Aug 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100