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

📄 default.aspx

📁 另一新版ajax组件
💻 ASPX
字号:
<%@ Page language="c#" AutoEventWireup="false" Inherits="AJAXDemo.Examples.Collections._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 - Collections 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>Collection Examples</h1>

<p>Ajax.NET can now return any collection that is using implementing IList, IEnumerable or IDictionary. To send a object back to the server you have to implement the IList interface which will use the data type of the .Add methods argument.</p>

<h2>Int16Collection and MyClassCollection</h2>

<p>A Int16Collection is similar to an array of integer values, but offers more methods like .Contains or .Add and .Remove. On the client-side JavaScript collections are currently implemented as arrays:</p>

<pre class="javascript">function doTest1() {
  var b = AJAXDemo.Examples.Collections.Demo.GetInt16Collection([1,2,3,4,5]).value;
  alert(b.join(','));
}</pre>

<p>Click <a href="javascript:doTest1();void(0);">here</a> to get a Int16Collection. I have added a collection for the MyClass, click <a href="javascript:doTest2();void(0);">here</a> to get the result.</p>

<h2>Using the original QueryString and Form values</h2>

<p>Because each Ajax.NET request is a new request to the web server the original querystring and form values are missing in the Ajax.NET context. You can write the NameValueCollections to your page:</p>

<pre class="csharp">protected override void OnPreRender(EventArgs e)
{
  base.OnPreRender (e);

  // Write the QueryString and Form collection to the page
  // using the Ajax.NET JavaScript serializer.

  StringBuilder sb = new StringBuilder();

  sb.Append("&lt;script type=\"text/javascript\"&gt;\r\n");
  sb.Append("var queryString = ");
  sb.Append(JavaScriptSerializer.Serialize(Request.QueryString));
  sb.Append(";\r\nvar form = ");
  sb.Append(JavaScriptSerializer.Serialize(Request.Form));
  sb.Append(";\r\n&lt;/script&gt;\r\n");

  Page.RegisterClientScriptBlock("request", sb.ToString());
}</pre>

<p>On the client you can access these values or submit it again to the Ajax.NET method:</p>

<pre class="javascript">function test() {
  alert(queryString["mykey"]);
  alert(form["mykey"]);
}</pre>


</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.Collections.Demo.GetInt16Collection([1,2,3,4,5]).value;
	alert(b.join(','));
}

function doTest2() {
	var b = AJAXDemo.Examples.Collections.Demo.GetMyClassCollection(null).value;
	var xml = AJAXDemo.Examples.Collections.Demo.GetAnyJavaScriptObject(b).value;
	alert(xml);
}

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

⌨️ 快捷键说明

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