I know this is out of date, but for those who want to do this on the server side, and not through the markup, you can do it.
var hyperLink = new HyperLink { Text = "Display text", ID = "hyperlinkId"}; hyperLink.Attributes.Add("onclick", "javascriptMethod()");
source share