.cs file
[ScriptMethod, WebMethod]
public static string CallingserverMethod(string name)
{
return "Hi" + name + Environment.NewLine + "This is an example";
}
.aspx file
<script type="text/javascript">
function servermethod()
{
PageMethods.CallingserverMethod(onSuccess, onFailure);
}
function onSuccess(result) {
alert(result);
}
function onFailure(error) {
alert(error);
}
</script>
Then call this servermethod() on click of button in your .aspx code.