📄 example.aspx
字号:
<%@ Page language="c#" Inherits="System.Web.UI.Page" ClassName="Example" %>
<script language="c#" runat="server">
public class MyClass
{
public string FirstName = "Michael";
public int Age = 28;
}
public struct MyStruct
{
public string FirstName;
public int Age;
}
[AjaxPro.AjaxMethod]
public string Test01(string input)
{
return "Hello " + input;
}
[AjaxPro.AjaxMethod]
public DateTime Test02(DateTime d)
{
return d.AddMinutes(10);
}
[AjaxPro.AjaxMethod]
public int[] Test03(int[] i)
{
return i;
}
[AjaxPro.AjaxMethod]
public ArrayList Test04(ArrayList list)
{
return list;
}
[AjaxPro.AjaxMethod]
public Decimal Test05(Decimal d)
{
return d * 2;
}
[AjaxPro.AjaxMethod]
public System.Data.DataSet Test06(System.Data.DataSet ds)
{
return ds;
}
[AjaxPro.AjaxMethod]
public bool Test07(bool b)
{
return !b;
}
[AjaxPro.AjaxMethod]
public string Test08(string[] s)
{
string ss = "";
foreach (string _s in s)
ss += _s + "#";
return ss.Substring(0, ss.Length -1);
}
[AjaxPro.AjaxMethod]
public System.Collections.Generic.List<string> Test09(System.Collections.Generic.List<string> s)
{
return s;
}
[AjaxPro.AjaxMethod]
public System.Collections.Generic.List<double> Test10(System.Collections.Generic.List<double> d)
{
return d;
}
[AjaxPro.AjaxMethod]
public char Test11(char c)
{
return c;
}
[AjaxPro.AjaxMethod]
public char Test12()
{
return (char)0;
}
[AjaxPro.AjaxMethod]
public string Test13(char c)
{
return "\0";
}
[AjaxPro.AjaxMethod]
public MyClass Test14()
{
return new MyClass();
}
[AjaxPro.AjaxMethod]
public MyClass Test15(MyClass c)
{
return c;
}
[AjaxPro.AjaxMethod]
public System.Data.DataTable Test16()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("FamilyName", typeof(string));
dt.Columns.Add("Birthday", typeof(DateTime));
// dt.Columns.Add("PersonInfo", typeof(MyClass));
System.Data.DataRow row = dt.NewRow();
row["FamilyName"] = "Schwarz";
row["Birthday"] = new DateTime(1977, 4, 20);
MyClass c = new MyClass();
c.FirstName = "Michael";
c.Age = 28;
// row["PersonInfo"] = c;
dt.Rows.Add(row);
return dt;
}
[AjaxPro.AjaxMethod]
public string Test17(System.Data.DataTable dt)
{
System.Data.DataSet ds = new System.Data.DataSet();
ds.Tables.Add(dt);
return ds.GetXml();
}
[AjaxPro.AjaxMethod]
public System.Xml.XmlDocument Test18()
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml("<ROOT/>");
System.Xml.XmlElement e = doc.CreateElement("FirstName");
e.InnerText = "Michael";
doc.DocumentElement.AppendChild(e);
e = doc.CreateElement("SpecialChars");
e.InnerText = "öäüÖÄÜß!\"<>§$";
doc.DocumentElement.AppendChild(e);
return doc;
}
public void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Example));
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
BODY {font-family:Tahoma,Arial;font-size:10pt;}
PRE {font-family:Courier New,Courier;font-size:8pt;}
</style>
</head>
<body>
<form id="Form1" method="post" runat="server">
<div id="loading" style="position:absolute;left:1px;top:1px;border:1px solid black;color:White;background-color:Red;margin:2px;display:none;">Loading...</div>
<div id="display"></div>
<script type="text/javascript">
var i = 0;
var oldResult = null;
var tests = [
{
desc: "Checks if a string will be parsed correct in both directions.",
run:function() { ASP.Example.Test01("Michael öäüß!\"§$%&/()=+´`@€'", callback); },
callback:function(res) { return res.value == "Hello " + "Michael öäüß!\"§$%&/()=+´`@€'"; }
},
{
desc: "Checks if a Date object will be parsed correct in both directions.",
run:function() { var d = new Date();
ASP.Example.Test02(d, callback, d);
},
callback:function(res) { return res.value.getTime() == res.context.getTime() + 10*60*1000; }
},
{
desc: "Checks if an integer array will be parsed correct in both directions.",
run:function() { var i = [1,2,3,4,5,6];
ASP.Example.Test03(i, callback, i);
},
callback:function(res) { return compareArray(res.value, res.context); }
},
{
desc: "Checks if an ArrayList will be parsed correct in both directions.",
run:function() { var i = [1,2,3,"Hello World",true,-2000];
ASP.Example.Test04(i, callback, i);
},
callback:function(res) { return compareArray(res.value, res.context); }
},
{
desc: "Checks if a Decimal value will be parsed correct in both directions.",
run:function() { var i = -2.445566;
ASP.Example.Test05(i, callback, i);
},
callback:function(res) { return res.value == res.context *2; }
},
{
desc: "Checks if a DataSet can be passed in both directions.",
run:function() {
var ds = new Ajax.Web.DataSet();
var dt = new Ajax.Web.DataTable();
dt.addColumn("FirstName", "System.String");
dt.addColumn("Age", "System.Int32");
ds.addTable(dt);
var r = {};
r.FirstName = "Michael";
r.Age = 28;
dt.addRow(r);
ASP.Example.Test06(ds, callback, ds);
},
callback:function(res) {
return res.value.Tables[0].Rows[0].FirstName == "Michael" && res.value.Tables[0].Rows[0]["Age"] == 28 && !isNaN(res.value.Tables[0].Rows[0].Age && compareArray(res.value.Tables[0].Rows[0], res.context.Tables[0].Rows[0]));
}
},
{
desc: "Checks if a Boolean can be passed in both directions.",
run:function() { ASP.Example.Test07(true, callback); },
callback:function(res) { return res.value == false; }
},
{
desc: "Checks if a string array can be passed to the AJAX method.",
run:function() { var l = ["Hello", "Michael", "Schwarz"];
ASP.Example.Test08(l, callback, l);
},
callback:function(res) { return res.value == res.context.join("#"); }
},
{
desc: "Checks if a generic string list can be passed in both directions.",
run:function() { var l = ["Hello", "Michael", "Schwarz"];
ASP.Example.Test09(l, callback, l);
},
callback:function(res) { return compareArray(res.value, res.context); }
},
{
desc: "Checks if a generic double list can be passed in both directions.",
run:function() { var l = [-1,-0.22223,0,1,2,3,4.5678,9.001];
ASP.Example.Test10(l, callback, l);
},
callback:function(res) { return compareArray(res.value, res.context); }
},
{
desc: "Checks if a char can be passed in both directions.",
run:function() { ASP.Example.Test11("s", callback);
},
callback:function(res) { return "s" == res.value; }
},
{
desc: "Checks if a null char can be returned.",
run:function() { ASP.Example.Test12(callback);
},
callback:function(res) { return "" == res.value; }
},
{
desc: "Checks if a null string can be returned.",
run:function() { ASP.Example.Test13("", callback);
},
callback:function(res) { return "" == res.value; }
},
{
desc: "Checks if embedded MyClass object can be returned.",
run:function() { ASP.Example.Test14(callback);
},
callback:function(res) {
oldResult = res.value;
return res.value.FirstName == "Michael";
}
},
{
desc: "Checks if embedded MyClass can be used as an argument.",
run:function() {
oldResult.FirstName = "Hans";
ASP.Example.Test15(oldResult, callback);
},
callback:function(res) {
return res.value.FirstName == "Hans";
}
},
{
desc: "Checks if we can get a DataTable with custom classes.",
run:function() { ASP.Example.Test16(callback); },
callback:function(res) {
oldResult = res.value;
return res.value.Rows[0].FamilyName == "Schwarz";
}
},
{
desc: "Checks if a DataTable retrieved from server can be used as an argument.",
run:function() { ASP.Example.Test17(oldResult, callback); },
callback:function(res) {
return true;
}
},
{
desc: "Checks if an XmlDocument can be returned.",
run:function() { ASP.Example.Test18(callback); },
callback:function(res) {
if(MS.Browser.isIE)
return res.value.documentElement.selectSingleNode("SpecialChars").text == "öäüÖÄÜß!\"<>§$";
return res.value.documentElement.getElementsByTagName("SpecialChars")[0].firstChild.data == "öäüÖÄÜß!\"<>§$";
}
}
];
AjaxPro.onLoading = function(b) {
window.status = b ? "Loading..." : "";
$("loading").style
}
function compareArray(a, b) {
if(a == null || b == null) return false;
if(a.length != b.length) return false;
for(var i=0; i<a.length; i++) {
if(typeof a[i] != typeof b[i]) return false;
if(a[i] != b[i]) return false;
}
return true;
}
function callback(res) {
if(tests[i].callback(res) == true) {
$("display").innerHTML += "<b style=\"color:green\">Test " + (i+1) + " finished</b><br/>";
if(tests[i].desc) $("display").innerHTML += " <i>" + tests[i].desc + "</i><br/>";
} else {
$("display").innerHTML += "<b style=\"color:red\">Test " + (i+1) + " failed" + (res.error != null ? " (" + res.error.Message + ")" : "") + "</b><br/>";
if(tests[i].desc) $("display").innerHTML += " <i>" + tests[i].desc + "</i><br/>";
$("display").innerHTML += "<pre>" + AjaxPro.toJSON(res).replace(/\\r\\n/g,"<br/>").replace(/</g,"<").replace(/>/g,">") + "</pre>";
}
$("display").innerHTML += "<hr size=\"1\"/>";
i++;
setTimeout(run, 1);
}
function run() {
if(i<tests.length) {
tests[i].run();
}
}
setTimeout(run, 1);
</script>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -