Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How call Javascript from Code Behind ?
Posted
Comments
Sergey Alexandrovich Kryukov 9-May-14 1:47am    
You never do. Javascript is executed on the client side in the browser. ASP.NET (server side) only generates Javascript.
—SA
[no name] 9-May-14 2:11am    
but the below solution works....
ClientScriptManager.RegisterStartupScript(this.GetType(),"your script block name","your script");

i can call my javascript function from code behind using above method,

ClientScriptManager.RegisterStartupScript(this.GetType(),"your script block name","your script");
 
Share this answer
 
You may also do as below.
C#
Page.ClientScript.RegisterStartupScript(this.GetType(),"Script Name" ,"script or  JS Function ", true);


In case of when Ajax comes in picture, you must use
C#
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "Script Name", "Js Function.", true);
 
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