Simply create webmethod in your codebehind file
[WebMethod]
public string Test()
{
return "Hi";
}
that webmethod in ajax.
$.ajax({
type: 'POST',
url: "yourpage.aspx/Test",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg);
}
});