简体   繁体   English

通过单击按钮调用Web控件的JavaScript函数

[英]Call Web control's JavaScript Function From Button Click

I've got a Web control called Fou.ascx and it has a java script function called DoFou(message). 我有一个名为Fou.ascx的Web控件,它具有一个名为DoFou(message)的Java脚本函数。 In my web Page I want to click a button, which is on the page and not part of the web control, and have it execute DoFou and pass in the message parameter. 在我的网页中,我想单击一个按钮,该按钮位于页面上而不是Web控件的一部分,并使其执行DoFou并传递message参数。 The web page has an instance of the web control Fou. 该网页具有Web控件Fou的实例。

How can I do this? 我怎样才能做到这一点?

thanks 谢谢

If the button is a server control, in the code behind you can do something like 如果按钮是服务器控件,则可以在后面的代码中执行以下操作

myButton.Attributes.Add("onClick", "doFou('" + myMessage + "');");

If the button is not a server control and assuming that myMessage is accessible in the ascx you can do something like 如果该按钮不是服务器控件,并且假定myMessage可在ascx中访问,则可以执行以下操作

<input type="button" onclick='<%= "doFou(\"" + myMessage + "\");" %>' value="myButton" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在按钮单击时从代码隐藏调用 Javascript function - Call Javascript function from codebehind on button click 从 web 页面按钮点击调用 Chrome 扩展中的 JavaScript 方法 - Call JavaScript method in Chrome extension from web page button click 如何在按钮单击时从JavaScript函数调用Ajax? - How to call ajax from a javascript function on button click? 如何在Button上单击JavaFX WebView调用JavaScript函数? - How to call a JavaScript function from a JavaFX WebView on Button click? 如何从 svelte 在 javascript 中单击按钮时调用异步函数? - How to call an async function on button click in javascript from svelte? 如何从gridview按钮单击事件代码背后调用javascript函数 - how to call javascript function from gridview button click event codebehind 从Button click事件中调用Codebehind中的Javascript函数 - Call Javascript function in Codebehind from Button click event 如何在按钮单击时从数组 javascript 调用 function - How to call function from array javascript on button click 是否可以从JavaScript网络工作者调用ActionScript函数? - It's possible to call ActionScript function from JavaScript web workers? 单击功能区中的按钮时如何调用JavaScript函数 - How to call javascript function on click of button in ribbon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM