text.ascx CODE:如何使用jQuery阿賈克斯與asp.net用戶控件
<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代碼:
[System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
return "Hello " + name + Environment.NewLine + "The Current Time is: "
+ DateTime.Now.ToString();
}
如何調用用戶控件中的jquery ajax。
的不可能性重複:http://stackoverflow.com/questions/3201218/how-can-i-call-webmethod-which-is-defined-in-user-control –