Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to call Server side function from the javascript function in asp.net

Thanks,
Posted

Its better to use AJAX instead.Its simple and easy to implement. Although
you can initiate a postback using __dopostback from javascript..
 
Share this answer
 
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);
      }
    });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900