Create page method
[System.Web.Services.WebMethod]
public static string myFunction (string name)
{
return "Hello " + name + Environment.NewLine + "The Current Time is: "
+ DateTime.Now.ToString();
}
And call this method in aspx as below using jquery
<button onclick="myFunction();">
Click me!
</button>
function myFunction() {
$.ajax({
type: "POST",
url: "CS.aspx/myFunction ",
data: '{name: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function(response) {
alert(response.d);
}
});
}