The "standard" way to do this in ASP.NET now, is to use AJAX. It's possible to use MS AJAX to accomplish this, but I prefer to use jQuery's Ajax calls.
What you do is create a
ScriptService
in your ASP.NET project, add the serverside code as a
WebMethod
, and then call it from your javascript. If you don't want to add a
ScriptService
, you can add the
WebMethod
to a
Page
. Here's a typical ajax call from jQuery:
$.ajax({
type: "POST",
url: "MyScriptService.asmx/GetDate",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
}
});