Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

How to call javascript function from code behind in .net 2.0 framework? I have tried following ways, but none of them are working.

C#
1. 
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsStartupScriptRegistered(this.GetType(), "Alert"))
 cs.RegisterStartupScript(this.GetType(), "Alert", "alert('Please Enter valid data');", true);

2.

ClientScriptManager cs = Page.ClientScript;
cs.RegisterClientScriptBlock(this.GetType(), "MsgWindow", "alert('Please Enter valid data');", true);

3.

Response.Write("<script type='text/javascript'>alert('Please Enter valid data');</script>");


thanks
Posted
Updated 13-Jun-13 22:58pm
v3

Try this :
C#
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "myFunction", "<script type='text/javascript'>function_name();</script>", false);


Or you can watch similar solved question for more detail here :[^]
 
Share this answer
 
v2
Comments
PleaseHelpCP 14-Jun-13 5:39am    
thanks Adhikari Surendra1 for reply, but this solution isn't working
Surendra Adhikari SA 14-Jun-13 6:02am    
what you get from debugger or Error?
PleaseHelpCP 14-Jun-13 7:01am    
i am not getting any error. it is not calling javascript.
 
Share this answer
 
Comments
PleaseHelpCP 14-Jun-13 5:40am    
thanks Shafeequl for reply, but this solution isn't working
Got the solution. I just added reference to System.Web.Extensions & it worked fine.
 
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