i am sure there is more good ways to do this. But i use below code to do this.
This is for calling a javascript function.
Button btn = new Button();
btn.Text = "click";
btn.Attributes.Add("onclick", "call_csharp_function()");
in your javascript
function call_csharp_function(){
<%=csharp_function_name()%>
}