0

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()
{
    //...
}
Bug
  • 832
  • 2
  • 9
  • 37

1 Answers1

2

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?

aebrinson
  • 36
  • 1