Ajax.NET Submit or return a class

Source: Internet
Author: User
Tags add object net return string client
Ajax

This is based on the demo written by the Ajax.NET author, the idea is to be able to submit a server-side definition from the client to the server side, the server can return a class to the client, I simplified the author's code, in the ASPX page does not use the CS file, while all the server-side methods are placed in a CS file In The code is annotated, and I find this AJAX framework really simple, as if now it looks like he's going to be simpler than Atlas and no refresh callbacks, all the code is IE6 and Firefox.
The front classtest.aspx code is as follows:
<%@ Page language= "C #"%>





untitled page














MyClass.cs file code: Only methods called by the client should add [Ajaxpro.ajaxmethod] to the method
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;


Summary description for MyClass

///
Namespace Mydemo
{
public class MyClass
{
Public MyClass ()
{
//
Todo:add constructor Logic here
//
}
public string FirstName = "";
public string LastName = "";
public int age = 0;
}
The following class inherits from the MyClass class, and he will have the same public properties as the class above
public class Myinheritedclass:myclass
{
public double Size = 0.0;
Public Guid gid = guid.empty;
}

public class Demo
{
Public Demo () {}
[Ajaxpro.ajaxmethod]
Public MyClass Getmyclass ()
{
This method will return an instance of the MyClass class
MyClass C = new MyClass ();
C.firstname = "Mouse";
C.lastname = "Wuqi Eva";
C.age = 30;
return C;
}
This method will be returned to the client with an instance of an inherited class Myinheritedclass class
[Ajaxpro.ajaxmethod]
Public Myinheritedclass Getinheritedclass ()
{
Initializes a Myinheritedclass class object because it inherits, so he also has the parent class public property
Myinheritedclass C = new Myinheritedclass ();
C.firstname = "Mouse";
C.lastname = "Wuqi Eva";
C.age = 30;
C.size = 4.5;
C.gid = Guid.NewGuid ();
return C;
}
The following method obtains data from the client (class object) and returns a class object to the client
[Ajaxpro.ajaxmethod]
Public MyClass Putclass (MyClass c)
{
C.lastname = "Wuqi Baby master";
return C;
}
}
}



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.