从代码后面调用javascript函数 [英] call javascript function from code behind

查看:68
本文介绍了从代码后面调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如何从.net 2.0框架中的代码调用javascript函数?我尝试了以下方法,但没有一个工作。



  1 
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsStartupScriptRegistered( this .GetType(), Alert))
cs.RegisterStartupScript( this .GetType(), 警报 alert('请输入有效数据'); true );

2

ClientScriptManager cs = Page.ClientScript;
cs.RegisterClientScriptBlock( this .GetType(), MsgWindow alert('请输入有效数据'); true );

3

Response.Write( < script type ='text / javascript'> alert ('请输入有效数据');< / script>);





谢谢


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





或者你可以观看类似已解决的问题以获取更多详细信息此处: [ ^ ]


您可以参考:



http://stackoverflow.com/questions/10287669/asp- net-call-javascript-function-from-code-behind [ ^ ]

happy Codding ....


得到解决方案。我刚刚添加了对System.Web.Extensions的引用,它运行正常。


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.

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

解决方案

Try this :

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 :[^]


You may refer this:

http://stackoverflow.com/questions/10287669/asp-net-call-javascript-function-from-code-behind[^]
happy Codding....


Got the solution. I just added reference to System.Web.Extensions & it worked fine.


这篇关于从代码后面调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆