Click here to Skip to main content
15,885,936 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to write Javascript code at .cs file....With Yes No Result.....
Posted

 
Share this answer
 
Yes, You can write javaScript code on code behind file. like

C#
string javaScriptString = "function showMethod() {alert('You pressed Me!'); }";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "myScriptName", javaScriptString, true);


You can also use RegisterStartupScript

Both RegisterClientScript and RegisterStartupScript use to add javascript code in web form between <form runat="server"> tag and </form> tag.

RegisterClientScript adds javascript code just after <form runat="server"> tag while RegisterStartupScript adds javascript code just before </form> tag.
 
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