text.ascx CODE:
<script type = "text/javascript">
function ShowCurrentTime() {
$.ajax({
type: "POST",
url: "TestAjax.aspx/GetCurrentTime",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
<input type="checkbox" id='chkl' onclick=ShowCurrentTime();>';
text.ascx.cs code :
[System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
return "Hello " + name + Environment.NewLine + "The Current Time is: "
+ DateTime.Now.ToString();
}
how to call jquery ajax in usercontrol.