Call c# method when clicking on hyperlink

I want a hyperlink that, when clicked, calls a C# method. Can anyone tell me how to do this?

The example below does not work …

html:

<a hef="<% MetthodToCall(); %>">Call C# Method</a>

Code behind:

public void MetthodToCall()
{
Response.Write(“MetthodToCall() was called!”);
}

I don’t believe the Hyperlink has an OnClick Server event; use a LinkButton instead.

  1. Place a LinkButton on your page.
  2. Switch to Design view
  3. Double-click on the LinkButton.
  4. Note that a click event is created for you in the code-behind.

Add DataBind(); to MetthodToCall().


public void MetthodToCall()
{
    Response.Write("MetthodToCall() was called!");
    [B]DataBind();[/B]
}

<a href=“<%#MetthodToCall(); %>”>Call C# Method</a>

char after the %