Methods for using custom collection in ajaxpro. net
Class 1:
Public class qqfriend
{
Private int userid;
Private string username;
Private string nickname;
Public qqfriend ()
{
}
Public qqfriend (INT userid, string username, string nickname)
{
This. userid = userid;
This. Username = username;
This. Nickname = nickname;
}
Public int userid
{
Get {return this. userid ;}
Set {This. userid = value ;}
}
Public String Username
{
Get {return this. Username ;}
Set {This. Username = value ;}
}
Public String nickname
{
Get {return this. Nickname ;}
Set {This. Nickname = value ;}
}
}
Web forms:
Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Namespace ceduuunew
{
Public class webform1: ceduu. Common. pagebase
{
Private void page_load (Object sender, system. eventargs E)
{
Ajaxpro. Utility. registertypeforajax (typeof (ceduunew. webform1 ));
Ajaxpro. Utility. registertypeforajax (typeof (ceduunew. Common. qqfriend ));
}
[Ajaxpro. ajaxmethod]
Public arraylist getqqfriendlist ()
{
Arraylist FL = new arraylist ();
Fl. Add (new common. qqfriend (1, "laijames", "James "));
Fl. Add (new common. qqfriend (2, "Chen", "chen1 "));
Return FL;
}
# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. button1.click + = new system. eventhandler (this. button#click );
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion
}
}
ASPX page:
<% @ Page Language = "C #" codebehind = "webform1.aspx. cs" autoeventwireup = "false" inherits = "ceduunew. webform1" %>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> webform1 </title>
<Meta content = "Microsoft Visual Studio. NET 7.1" name = "generator">
<Meta content = "C #" name = "code_language">
<Meta content = "JavaScript" name = "vs_defaultclientscript">
<Meta content = "http://schemas.microsoft.com/intellisense/ie5" name = "vs_targetschema">
<Script language = "JavaScript">
Function getuserdefinetype ()
{
Ceduuunew. webform1.getqqfriendlist (mycallbackuserdefinetype );
}
Function mycallbackuserdefinetype (RES)
{
VaR friendlist = res. value;
For (I = 0; I <friendlist. length; I ++)
{
Friend = friendlist [I];
Alert ("userid:" + friend. userid + "/R/N" + "username:" + friend. username + "/R/N" + "nickname:" + friend. nickname );
}
}
</SCRIPT>
</Head>
<Body ms_positioning = "gridlayout">
<Form ID = "form1" method = "Post" runat = "server">
<Input style = "Z-INDEX: 102; left: pixel PX; position: absolute; top: 192px" onclick = "getuserdefinetype ()"
Type = "button" value = "server return custom data type">
</Form>
</Body>
</Html>