Data Type Examples

NEW! For a newer version of data type examples see http://munich.schwarz-interactive.de/datatype.aspx.

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.

Primitive Data Types

Click here to check if the bool data type is working. The second on is int, double and char.

Now, we want to use two integer and two double values as arguments, click here. We can also use arrays as argument values:

[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;
}

Click here 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:

function doTest7() {
	// using synchronous invoke
	var b = AJAXDemo.Examples.DataType.Demo.GetDateTime(new Date()).value;
	alert(b);
}
[AjaxMethod]
public DateTime GetDateTime(DateTime d)
{
  return d.AddHours(4);
}

Let us see if this is working correct, run the test.

I have written a small method that will convert any IJavaScriptObject to an XML document:

[AjaxMethod]
public string GetAnyJavaScriptObject(IJavaScriptObject o)
{
  XmlDocument doc = new XmlDocument();
  doc.LoadXml("");

  AddObjectToXml(doc.DocumentElement, o);
			
  return doc.OuterXml;
}
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);
}

Click here to get the XML output of the JavaScript object in the method above.

Valid XHTML 1.0 Transitional