Collection Examples

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.

Int16Collection and MyClassCollection

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:

function doTest1() {
  var b = AJAXDemo.Examples.Collections.Demo.GetInt16Collection([1,2,3,4,5]).value;

Click here to get a Int16Collection. I have added a collection for the MyClass, click here to get the result.

Using the original QueryString and Form values

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:

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("<script type=\"text/javascript\">\r\n");
  sb.Append("var queryString = ");
  sb.Append(";\r\nvar form = ");

  Page.RegisterClientScriptBlock("request", sb.ToString());

On the client you can access these values or submit it again to the Ajax.NET method (click here to open this page with an argument):

function test() {

Valid XHTML 1.0 Transitional