如何在代码背后调用Javascript函数 [英] How Do I Call Javascript Function At Code Behind

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

问题描述

我创建了一个javascript函数,用于通过使用字符串构建器从代码隐藏中拖动控件。





但我不知道我该怎么称呼这个功能





请有人帮我...





提前感谢

解决方案

如果你在aspx页面上有java脚本函数,可以说MyFunc()



如果您想在特定按钮上调用此功能,请点击



写入添加属性到您的按钮代码隐藏在页面后面如下所示



 btnSave.Attributes.Add(  onclick 返回MyFunc()); 





如果你想在下拉值改变时调用java脚本然后调用如下



 ddlStatus.Attribut es.Add(  OnChange  MyFunc()); 







如果你想在页面加载中调用页面加载调用函数上的java脚本



 ClientScript.RegisterStartupScript(GetType(),   key  Test(); true ); 


< blockquote>参考 - 从asp.net中的codebehind调用javascript函数 [ ^ ]。

Quote:

 System.Web.UI.ScriptManager.RegisterClien tScriptBlock(Page, typeof (页面), 脚本   MyJavascriptFunction();); 


i have created a javascript function for dragging an control from codebehind through the use of string builder.


but i dont know how can i call this function


please some one help me...


thanks in advance

解决方案

if you have java script function on aspx page lets say "MyFunc()"

and if you want to call this function on specific button click then

write Add attribute to your button in code behind page as show in below

btnSave.Attributes.Add("onclick","return MyFunc()");



if you want to call java script on dropdown value change then call as below

ddlStatus.Attributes.Add("OnChange","MyFunc()");




if you want to call java script on page load call function below in page load

ClientScript.RegisterStartupScript(GetType(), "key", "Test();", true);


Refer - Call javascript function from codebehind in asp.net[^].

Quote:

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "MyJavascriptFunction();", true);


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

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