一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

ASP.NET(AJAX+JSON)實現對象調用

客戶端:
復制代碼 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ASP.NETA_JAX.ASPx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/jscript">
function CallServer() {
//JSON發送對象
ServerSum("{name:'linyijia',age:'21'}");
}
function GetRegister(rg, contex) {
document.getElementById("TxtRegister").value=rg;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
用戶名:<input id="TxtNum1" type="text" />
<br />
服務器:<input id="TxtRegister" type="text" /><br />
<button id="SumBtn" type="button" onclick="CallServer()">登錄</button>
</div>
</form>
</body>
</html>

服務器:
復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
public partial class _Default : System.Web.UI.Page ,ICallbackEventHandler
{
Users u = null;
protected void Page_Load(object sender, EventArgs e)
{
//回調GetRegister方法
string CallBackFun = Page.ClientScript.GetCallbackEventReference(this,"arg","GetRegister","context");
//創建ServerSum方法,在客戶端調用的時候就,會回調GetRegister方法,把參數傳給RaiseCallbackEvent(string eventArgument ),最后通過
//GetCallbackResult()方法把返回值傳給客戶端
string RegisterFun = string.Format("function ServerSum(arg,context){{{0};}}",CallBackFun);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"ServerSum",RegisterFun,true);
}
string mssage = string.Empty;
#region ICallbackEventHandler 成員
public string GetCallbackResult()
{
return "服務器:你好,你的用戶名為:" + u.Name + "你的年齡為" + u.Age;
}
public void RaiseCallbackEvent(string eventArgument)
{
JavaScriptSerializer js = new JavaScriptSerializer();
u =js.Deserialize<Users>(eventArgument);
}
#endregion
}

Users類
復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
///User 的摘要說明
/// </summary>
public class Users
{
string name;
public string Name
{
get { return name; }
set { name = value; }
}
string age;
public string Age
{
get { return age; }
set { age = value; }
}
}

原理:
使用JSON向服務器發送一個對象,服務器通過實現 ICallbackEventHandler接口后,重寫GetCallbackResult和RaiseCallbackEvent方法,在回調的時候,在RaiseCallbackEvent方法
中反序列化JSON,并在GetCallbackResult把結果返回給客戶端.具體的我以后有空再補充,歡迎大家討論!

AspNet技術ASP.NET(AJAX+JSON)實現對象調用,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 青草久操 | 欧美性v视频播放 | 久久福利一区二区 | 色婷婷精品大全在线视频 | 国产精品免费视频网站 | 丁香婷婷基地 | 久久综合亚洲伊人色 | 道区二区三区四区 | 亚洲一区视频在线播放 | 天天干天天舔 | 国产91精品久久久久久 | 精品视频在线观看一区二区三区 | 亚洲乱码在线视频 | 一区二区视频免费看 | 热色视频 | 一区二区三区免费视频观看 | 国产男女爱视频在线观看 | 精品久久久一二三区 | 久久综合中文字幕 | se色成人亚洲综合 | 天堂网站天堂小说 | 欧美成人久久一级c片免费 欧美成人免费sss | 久99视频| 16女性下面扒开无遮挡免费 | 在线观看91精品国产hd | 国产精品第一区在线观看 | 精品女同一区二区三区免费站 | 麻豆视频播放 | 成人久久伊人精品伊人 | 日韩精品久久久免费观看夜色 | 久久久网站亚洲第一 | 欧美成人三级网站 | 午夜激情视频在线 | 天天色天天操综合网 | 五月婷婷激情综合 | 久久综合九色综合欧洲色 | 天天艹天天 | 激情五月亚洲 | 午夜色网站 | yy4080午夜一毛片 | 91在线永久 |