I have a C# method located in the code behind and I would like to call it from the.aspx content page. The following are my code:
<a class="btn-button button" onclick="myFunction()">Click</a>
function myFunction() {
<%=MyMethod()%>
}
public void MyMethod()
{
//...
}
You could use a LinkButton and use its click event to call code behind method:
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
C#:
protected void LinkButton1_Click(object sender, EventArgs e)
{
//Call your method here
}
What action are you trying to perform with the OnClick event?
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.