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. 开发者_JAVA百科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" />
精彩评论