最近由于项目需要,采用AjaxPro 在没有cs页面的情况下调用。
在网上找了一下,也没有合适的例子。所以决定记录下来。
1、添加配置webconfig,和添加引用(略)
2、添加无CS的页面。
3、在添加好的页面中
<%@ Page Language="c#" ClassName="LoadingDemo" Inherits="System.Web.UI.Page" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(LoadingDemo));
Response.Write(typeof(LoadingDemo));
}
[AjaxPro.AjaxMethod]
public DateTime LongOperation()
{
System.Threading.Thread.Sleep(1000);
return DateTime.Now;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>AjaxProDemo</title>
<style type="text/css">
html, body
{
margin: 0;
height: 100%;
}
</style>
<script language="javascript" type="text/javascript">
function doTest1() {
ASP.LoadingDemo.LongOperation(doTest1_callback);
}
function doTest1_callback(res) {
alert(res.value);
}
</script>
</head>
<body style="margin: 0">
<form id="form1" runat="server">
<input id="BtnQuery" type="button" class="Btn2" value="查询" onclick="doTest1();" />
</form>
</body>
</html>