[英]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.