Click Here for Download Source Code
Below is Default.aspx page code
-------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Call server side method using Jquery</title>
<!-- Add the jQuery Reference Library-->
<script src="Script/jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('#btnok').click(function() {
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" />
<span id="status"></span>
</div>
</form>
</body>
</html>
Code Behide file code (Default.aspx.cs)
-----------------------------------------
-------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Call server side method using Jquery</title>
<!-- Add the jQuery Reference Library-->
<script src="Script/jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('#btnok').click(function() {
$.ajax({
type: "POST",
url: "Default.aspx/Test1",
data: "{'args1':'Kalpesh','args2':'Patel'}",
contentType: "application/json",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$("#newresult").text(msg.d);
}
});
});
</script></head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" />
<span id="status"></span>
</div>
</form>
</body>
</html>
Code Behide file code (Default.aspx.cs)
-----------------------------------------
using System;
using System.Web.Services;
using System.Web;
public partial class _Default : System.Web.UI.Page
{
public void test()
{
}
[WebMethod(EnableSession = false)]
public static string Test1(string args1, string args2)
{
return "Hello: " + args1 + " " + args2;
}
[WebMethod]
public static string Test2()
{
return "Hello: " + DateTime.Now.Millisecond + " -- Kalpesh Patel";
}
}