jQuery is a lightweight JavaScript library and can be downloaded from http://www.jquery.com.
I’ll show you how to use jQuery to call a page method without using the ScriptManager.
This will be our page method in ASP.NET code behind.
public partial class _Default : Page
{
[WebMethod]
public static string GetData()
{
return String.Format("Sever time is..{0}", DateTime.Now.ToString());
}
}
Here is our Default.aspx
<html>
<head>
<title>Demo with jQuery</title>
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="Demo.js"></script>
</head>
<body>
<div id="divResult">Click here to get server time</div>
</body>
</html>
You can increase the performance by replacing above Script with google AJAX Libraries.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
Google AJAX Libraries can be found here http://code.google.com/apis/ajaxlibs/
Here is our Demo.js
$(document).ready(function() {
$("#divResult").click(function() {
$.ajax({
type: "POST",
url: "Default.aspx/GetData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(res) {
$("#divResult").text(res.d);
}
});
});
});