Data type of Ajax.NET

Source: Internet
Author: User
Tags add foreach array object bool datetime net return
ajax| Data | data type


This example is done according to the data type example of Ajax.NET's author, presumably meaning that many data types can be passed as parameters to the server-side Ajax.NET method, and the same data type can be returned from the Ajax.NET server-side method. In particular, he was able to convert a client object into an XML document, the author called him Ijavascriptobject, the code is as follows, with detailed comments
Front datatype.aspx Code:
<%@ Page language= "C #"%>

untitled page

class file MyDataType.cs code:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using Ajaxpro;
Using System.Xml;



Summary description for Mydatatype

///
Namespace Mydemo
{
public class Mydatatype
{
Public Mydatatype ()
{
//
Todo:add constructor Logic here
//
}
[Ajaxpro.ajaxmethod]
public bool Getbool (BOOL B)
{
From True returns false, ship to false, return true
return!b;
}
[Ajaxpro.ajaxmethod]
public int GetInt (int i)
{
Send the int parameter plus 10 to return
return i + 10;
}
[Ajaxpro.ajaxmethod]
Public double getdouble (double D)
{
and return the double+0.1.
return D + 0.1;
}
[Ajaxpro.ajaxmethod]
Public Char GetChar (char c)
{
Bring the Char plus 1 back.
return ++c;
}
[Ajaxpro.ajaxmethod]
public int GetNumber (int i, double b, float f)
{
Calculate their and with int return
return (int) (double) i+b+f);
}
[Ajaxpro.ajaxmethod]
Public object[] Getnumbers (int[] I, double[] D)
{
The arguments passed are an int array and a double array, and we compute the and of the two arrays, respectively.
Then make them an element of an object array.
object[] o = new object[2];//Initializes an object array with two elements
O[0] = 0;//assigns a value to the first element he will be used to load the array of int and
O[1] = 0;//assigns a value to the second element he will be used to load the double array and
All over the int array, put his and put in the first element of object
int i1=0;
foreach (int a in i)
{
I1 + A;
}
O[0] = I1;
Double array.
Double D1 = 0;
foreach (double b in D)
{
D1 + b;
}
O[1] = D1;
return o;
}
[Ajaxpro.ajaxmethod]
public datetime getdatetime (datetime d)
{
Add four hours to the time to return
Return D.addhours (4);
}
[Ajaxpro.ajaxmethod]
public string GetXml (Ijavascriptobject o)
{
The object of the client was made into a ijavascriptobject type by him
Convert him to XML DOM, using the Javascriptutil method to note the use Ajaxpro
XmlDocument xml = Javascriptutil.convertijavascriptobjecttoxml (o);
return XML. OuterXml;
}
}
}
The results of the operation are as follows:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.