从后面的代码调用Javascript方法 [英] Call Javascript method from code behind

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

问题描述

我在Javascript中有一个函数,它使标签不可见。我想从后面的代码中调用这个函数。我无法让它隐形。以下是两行代码。



代码落后:



I have a function in Javascript which makes a label invisible. I want to call this function from the code behind. I am not able to make it invisible. Here are both the lines of code.

Code behind:

ClientScript.RegisterStartupScript(GetType(), DateTime.Now.ToString(), "MyFunction();", true);





Javascript:





Javascript:

function MyFunction()
       {
           document.getElementById("<%= Label8.ClientID %>").style.display = 'none'; 
       }





如果有任何错误,请告诉我。看起来控件不仅仅是方法定义。



谢谢



Pls let me know if there is any mistake. Looks like control is not going to method definition only.

Thank you

推荐答案





尝试以下代码。可能对你有帮助。



Hi,

try the following code. May be it help you.

ScriptManager.RegisterStartupScript(this.Page, this.GetType(),"Myfun", "MyFunction();", false);







Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "MyFunction();", true);


检查页面上是否有多个RegisterStartupScript块。

如果是,那么你必须以不同的方式命名每个脚本块







check clientscriptmanager.IsStartupScriptRegister为此,你可以重载RegisterStartupScript
check if there are multiple RegisterStartupScript blocks on your page.
If yes then you will have to name each script block differently



check clientscriptmanager.IsStartupScriptRegistered for that and in that case you can overload RegisterStartupScript


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

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