AJAXPRO.NET中使用自定类型集合的方法
类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窗体类:
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 CeduuNew
{
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;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
aspx页面:
<%@ 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()
{
CeduuNew.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: 112px; POSITION: absolute; TOP: 192px" οnclick="getUserDefineType()"
type="button" value="服务器返回自定义数据类型">
</form>
</body>
</HTML>