简体   繁体   中英

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). 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. The web page has an instance of the web control 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM