How to call code behind method from jquery

Now let us see “How to call code behind method from jquery in”. It is very simple , try  it out.

<html xmlns="">
<head runat="server">
<title>call server side method from JQuery in</title>
<script type="text/javascript" language="javascript">
function callservermethod() {
var name = $get("txtName").value;
PageMethods.GetCurrentDate(name, OnSuccess, OnFailure);
function OnSuccess(result) {
if (result) {
function OnFailure(error) {

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
Enter Name of Person: <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:Button ID="btnClick" runat="server" Text="Click" OnClientClick ="callservermethod()" />

public static string DisplayData()
return DateTime.Now.ToString();

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>