⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx

📁 另一新版ajax组件
💻 ASPX
字号:
<%@ Page language="c#" AutoEventWireup="false" Inherits="AJAXDemo.Examples.DataType._default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Ajax.NET - DataType Example</title>
    <link rel="stylesheet" type="text/css" href="../../css/main.css"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  </head>
  <body>
	
<form id="Form1" method="post" runat="server"></form>

<div class="content">

<h1>Data Type Examples</h1>

<p>With this example web page I will test a lot of common data types in both directions, as a return value and as an argument for the Ajax.NET methods.</p>

<h2>Primitive Data Types</h2>

<p>Click <a href="javascript:doTest1();void(0);">here</a> to check if the bool data type is working. The second on is <a href="javascript:doTest2();void(0);">int</a>, <a href="javascript:doTest3();void(0);">double</a> and <a href="javascript:doTest4();void(0);">char</a>.</p>
<p>Now, we want to use two integer and two double values as arguments, click <a href="javascript:doTest5();void(0);">here</a>. We can also use arrays as argument values:</p>

<pre class="csharp">[AjaxMethod]
public object[] GetNumbers(int[] a, double[] b)
{
  object[] x = new object[2];
  x[0] = 0;
  x[1] = 0.0;

  foreach(int i in a) x[0] = (int)x[0] + i;
  foreach(double i in b) x[1] = (double)x[1] + i;

  return x;
}</pre>

<p>Click <a href="javascript:doTest6();void(0);">here</a> to run this example. Next we submit a JavaScript Date object to the server, add there four hours to the DateTime argument and return the new value:</p>

<pre class="javascript">function doTest7() {
	// using synchronous invoke
	var b = AJAXDemo.Examples.DataType.Demo.GetDateTime(new Date()).value;
	alert(b);
}</pre>

<pre class="csharp">[AjaxMethod]
public DateTime GetDateTime(DateTime d)
{
  return d.AddHours(4);
}</pre>

<p>Let us see if this is working correct, run the <a href="javascript:doTest7();void(0);">test</a>.</p>
<p>I have written a small method that will convert any IJavaScriptObject to an XML document:</p>

<pre class="csharp">[AjaxMethod]
public string GetAnyJavaScriptObject(IJavaScriptObject o)
{
  XmlDocument doc = new XmlDocument();
  doc.LoadXml("<ROOT/>");

  AddObjectToXml(doc.DocumentElement, o);
			
  return doc.OuterXml;
}</pre>

<pre class="javascript">function doTest8() {
  var o = new Object();
  o.MyArray = [1,2,3,4,5,6,7,8];
  o.MyBoolean = true;
  o.MyString = "Hello World";
  o.MyObject = {"FirstName":"Michael","Age":28};
  o.MyDate = new Date();

  var b = AJAXDemo.Examples.DataType.Demo.GetAnyJavaScriptObject(o).value;
  alert(b);
}</pre>

<p>Click <a href="javascript:doTest8();void(0);">here</a> to get the XML output of the JavaScript object in the method above.</p>


</div>
<p class="footer">Last updated: November 2, 2005 by <a href="http://weblogs.asp.net/mschwarz/contact.aspx" target="_blank">Michael Schwarz</a></p>
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></p>

<script type="text/javascript" defer="defer">

function doTest1() {
	var b = AJAXDemo.Examples.DataType.Demo.GetBoolean(false).value;
	alert(b);
}

function doTest2() {
	var b = AJAXDemo.Examples.DataType.Demo.GetInteger(200).value;
	alert(b);
}

function doTest3() {
	var b = AJAXDemo.Examples.DataType.Demo.GetDouble(1.1).value;
	alert(b);
}

function doTest4() {
	var b = AJAXDemo.Examples.DataType.Demo.GetChar('a').value;
	alert(b);
}

function doTest5() {
	var b = AJAXDemo.Examples.DataType.Demo.GetNumber(-2, -5, -2.2, -5.8).value;
	alert(b);
}

function doTest6() {
	var b = AJAXDemo.Examples.DataType.Demo.GetNumbers([1,2,3],[1.1,2.2,3.3]).value;
	alert(b[0] + " " + b[1]);
}

function doTest7() {
	var b = AJAXDemo.Examples.DataType.Demo.GetDateTime(new Date()).value;
	alert(b);
}

function doTest8() {

	var o = new Object();
	o.MyArray = [1,2,3,4,5,6,7,8];
	o.MyBoolean = true;
	o.MyString = "Hello World";
	o.MyObject = {"FirstName":"Michael","Age":28};
	o.MyDate = new Date();

	var b = AJAXDemo.Examples.DataType.Demo.GetAnyJavaScriptObject(o).value;
	alert(b);
}

</script>
  </body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -