Click here to Skip to main content
15,891,692 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to Call javascript function on page load.

I have tried
(on aspx.cs Page_load)
ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);


                     AND

(on .aspx before ending script tag)
ScriptManager.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);


Both dint gave me the result.. .
Posted
Comments
Chinmaya C 9-Apr-13 6:38am    
Have you tried with $(document).ready() ?
Anuja Pawar Indore 9-Apr-13 11:13am    
try this
Page.ClientScript.RegisterClientScriptBlock(typeof(ScriptManager), "CallMyMethod", "myMethod();");

Also try

JavaScript
$(document).ready(function () {

        });
 
Share this answer
 
Try this:
C#
ScriptManager.RegisterStartupScript(this, typeof(Page), "Testing", "FUNCTIONNAME();", true);




--Amit
 
Share this answer
 
Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page. and does NOT EXECUTE it.

http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerstartupscript.aspx[^]

http://msdn.microsoft.com/en-us/library/bb359558.aspx[^]

To execute it you will need a client side event.. Not the server side Page_Load or anything

EDIT:

Check if this is your case
http://brijbhushan.net/2011/11/24/page-clientscript-registerstartupscript-is-not-working/[^]
 
Share this answer
 
v2
Comments
_Amy 9-Apr-13 7:20am    
You might not seen the section function in first link.
RegisterStartupScript(Page, Type, String, String, Boolean) : Registers a startup script block for every asynchronous postback with the ScriptManager control and adds the script block to the page.

Check http://msdn.microsoft.com/en-us/library/bb310408.aspx[^]

--Amit
bbirajdar 9-Apr-13 8:32am    
I know that.. But the main question is whether the script EXECUTES ( CALLS, RUNS) or REGISTERS .. That is the main difference....No whether it is a page or control.. You should not be in too hurry to downvote...

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