This is based on the demo written by the ajax.net author. It generally means that a server-defined class can be submitted from the client to the server, and the server can return a class to the client, I simplified the author'sCodeThe CS file is not used on the ASPX page, and all server methods are put in a CS file! With comments in the code, I found that this Ajax framework is really simple. It seems that it is simpler than atlas and refreshing callbacks now. All the code passes through IE6 and Firefox
The foreground classtest. aspx code is as follows:
<% @ Page Language = "C #" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.1 // en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<SCRIPT runat = Server>
Void page_load (Object sender, eventargs E)
{
// Register the demo class under the namespace mydemo
Ajaxpro. Utility. registertypeforajax (typeof (mydemo. Demo ));
}
</SCRIPT>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> untitled page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Input type = button value = "Return Class Object" onclick = "getclass ()"/> <br/>
<Input type = button value = "return an inheritance Class Object" onclick = "getinheritedclass ();"/> <br/>
<Input type = button value = "Submit a Class Object to the server" onclick = "putclass ();"/>
</Div>
</Form>
<SCRIPT type = "text/JavaScript">
Function getclass ()
{
Mydemo. Demo. getmyclass (getmyclass );
}
Function getmyclass (RET)
{
VaR A = ret. value;
Alert (A. firstname );
}
Function getinheritedclass ()
{
Mydemo. Demo. getinheritedclass (getinhclass );
}
Function getinhclass (TG)
{
VaR A = Tg. value;
Alert (A. lastname + "\ n" + A. GID );
}
Function putclass ()
{
VaR P = mydemo. Demo. getmyclass (). value;
// First call the server method getmyclass to return a myclass object
P. firstname = "rat is ";
// The first parameter is required by the server method, and the second parameter is the JS function that receives data processing.
Mydemo. Demo. putclass (p, putmyclass );
}
Function putmyclass (DSF)
{
VaR A = DSF. value; // get data from the server
Alert (A. firstname + "\ n" + A. lastname + "apprentice! ");
}
</SCRIPT>
</Body>
</Html>
Myclass. CS file code: only the method called by the client must be added to the method [ajaxpro. ajaxmethod]
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>
/// Summary description for myclass
/// </Summary>
///
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 will have the same public attributes as the class above.
Public class myinheritedclass: myclass
{
Publicdouble size = 0.0;
Public guid gid = guid. empty;
}
Public class demo
{
Public demo (){}
[Ajaxpro. ajaxmethod]
Public myclass getmyclass ()
{
// This method returns an instance of the myclass class.
Myclass c = new myclass ();
C. firstname = "rat ";
C. lastname = "wuqiwa ";
C. Age = 30;
Return C;
}
// This method returns an instance of the inherited class myinheritedclass to the client.
[Ajaxpro. ajaxmethod]
Public myinheritedclass getinheritedclass ()
{
// Initialize a myinheritedclass object. Because it inherits, it also has the common attributes of the parent class.
Myinheritedclass c = new myinheritedclass ();
C. firstname = "rat ";
C. lastname = "wuqiwa ";
C. Age = 30;
C. size = 4.5;
C. gid = guid. newguid ();
Return C;
}
// The following method obtains the data (Class Object) sent from the client and returns a Class Object to the client.
[Ajaxpro. ajaxmethod]
Public myclass putclass (myclass C)
{
C. lastname = "Master Wu banwa ";
Return C;
}
}
}