记忆潜处
With great power comes great responsibility
博客园
首页
社区
新随笔
联系
订阅
管理
随笔-42 评论-128 文章-0 trackbacks-4
Microsoft Asp.Net Ajax框架入门(12) 了解异步通信层
VS 2008
本文通过两个简单的例子,了解Asp.Net Ajax Asynchronous Communication Layer
Asp.Net Ajax异步通信层提供了一系列客户端的类,用于客户端请求服务端
第一个例子:请求服务端页面
1) 被请求页 Ajax_GetUserName.aspx
html代码仅留页面声明,其余全部清楚:
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Ajax_GetUserName.aspx.cs
"
Inherits
=
"
Ajax_GetUserName
"
%>
Ajax_GetUserName.aspx.cs页面写处理逻辑:
public
partial
class
Ajax_GetUserName : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(Request.QueryString[
"
userId
"
]
==
"
1
"
)
{
Response.Write(
"
guozhijian
"
);
}
else
{
Response.Write(
string
.Empty);
}
}
}
2) 客户端请求
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.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
>
Untitled Page
</
title
>
<
script type
=
"
text/javascript
"
>
function btnGetNameClickHandler()
{
var req
=
new
Sys.Net.WebRequest();
req.set_url(
"
Ajax_GetUserName.aspx?userId=1
"
);
req.add_completed(requestCompleted);
req.invoke();
}
function requestCompleted(executor, eventArgs)
{
if
(executor.get_statusCode()
==
200
)
{
alert(executor.get_responseData());
}
}
</
script
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
asp:ScriptManager ID
=
"
smgr
"
runat
=
"
server
"
></
asp:ScriptManager
>
<
div
>
<
input type
=
"
button
"
id
=
"
btnGetName
"
onclick
=
"
btnGetNameClickHandler()
"
value
=
"
get name
"
/>
</
div
>
</
form
>
</
body
>
</
html
>
第二个例子:请求XML文档
1)新建UserInfos.xml
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
<
userInfos
>
<
userInfo
>
<
userId
>
1
</
userId
>
<
userName
>
guozhijian
</
userName
>
</
userInfo
>
<
userInfo
>
<
userId
>
2
</
userId
>
<
userName
>
zhenglanzhen
</
userName
>
</
userInfo
>
</
userInfos
>
2)客户端请求
function btnGetXmlClickHandler()
{
var req
=
new
Sys.Net.WebRequest();
req.set_url(
"
UserInfos.xml
"
);
req.add_completed(getXmlCompleted);
req.invoke();
}
function getXmlCompleted(executor, eventArgs)
{
if
(executor.get_statusCode()
==
200
)
{
alert(executor.get_xml().xml);
}
}
posted on 2008-02-17 19:19
Tristan(GuoZhijian)
阅读(273)
评论(0)
编辑
收藏
所属分类:
Asp.Net Ajax
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
闪存
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
相关文章:
在ASP.NET中使用无框架的Ajax事例
[添砖加瓦]:ExtJS+WCF+LINQ打造全功能Grid
使用Visual Studio2005入门.Net2.0系列视频教程
Microsoft .Net Remoting系列专题之一:.Net Remoting基础篇
Microsoft Videos Beta 站点上线
Microsoft SQL Server 2008 正式发布
Asp.Net在无Cookie状态下会话问题
如何将Asp.Net网站通用的一些功能模块化?
Asp.Net通用权限管理系统 专用代码生成工具(DDBuildTools) 1.0
Asp.Net权限管理系统 专用代码生成工具(DDBuildTools) 1.1.0
相关链接:
所属分类的其他文章:
Behavior模型应用:可拖动的div容器
Microsoft Asp.Net Ajax框架入门(13) PageRequestManager
Microsoft Asp.Net Ajax框架入门(12) 了解异步通信层
Microsoft Asp.Net Ajax框架入门(11) 调用内部Web Services
Microsoft Asp.Net Ajax框架入门(10) ScriptManager, UpdatePanel, Timer
Microsoft Asp.Net Ajax框架入门(9) 事件
Microsoft Asp.Net Ajax框架入门(8) 枚举
Microsoft Asp.Net Ajax框架入门(7) 名称空间、类、继承、接口
Microsoft Asp.Net Ajax框架入门(6) Debugging and Typed Errors
Microsoft Asp.Net Ajax框架入门(5) Object类型、String类型、Array类型
最新IT新闻:
Google开拓美政府机构市场 微软业务受冲击
消息称苹果正在开发iTunes网络电视
微软周一开电话会议 预计将发布Silverlight2.0
开心网即将启用”shejiao.com”?
Google股价跌破329美元 61%员工期权价值归零
Tristan obtained a master's degree of mathematics at DongHua university in Mar. 2006. Now he works at Cognizant co. as a software engineer. He is currently working with c# mostly in web application development.He has a good understanding of CLR, asp.net, javascript, ajax, xml, xslt, OOP, design pattern, etc.
You can contact him
by email: promiss#live.cn
<
2008年2月
>
日
一
二
三
四
五
六
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1
2
3
4
5
6
7
8
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(3)
给我留言
查看留言
我参加的小组
博客园上海俱乐部
我参与的团队
上海.NET俱乐部(1/2249)
随笔分类
(42)
Asp.Net(5)
Asp.Net Ajax(14)
C#(3)
Design Pattern(16)
SqlServer2005(2)
Windows Forms App(2)
随笔档案
(42)
2008年4月 (1)
2008年3月 (12)
2008年2月 (18)
2008年1月 (7)
2007年12月 (3)
2007年11月 (1)
.Net Professionals
Ian Griffiths' Weblog
积分与排名
积分 - 35606
排名 - 1213
最新随笔
1. Core Design Patterns(16) Chain of Responsibility 职责链模式
2. Core Design Patterns(15) Template Method 模版方法模式
3. Core Design Patterns(14) State 状态模式
4. Core Design Patterns(13) Strategy 策略模式
5. Core Design Patterns(12) Builder 建造者模式
6. Core Design Patterns(11) Abstract Factory 抽象工厂模式
7. Core Design Patterns(10) Singleton 单例模式
8. Core Design Patterns(9) Factory Method 工厂方法模式
9. Core Design Patterns(8) Prototype 原型模式
10. Core Design Patterns(7) Facade 外观模式
11. Core Design Patterns(6) Adapter 适配器模式
12. Core Design Patterns(5) Flyweight 享元模式
13. Core Design Patterns(4) Composite 组合模式
14. Core Design Patterns(3) Bridge 桥接模式
15. Core Design Patterns(2) Proxy 代理模式
16. Core Design Patterns(1) Decorator 装饰模式
17. 老调重弹:插件式框架开发的一个简单应用
18. Behavior模型应用:可拖动的div容器
19. Microsoft Asp.Net Ajax框架入门(13) PageRequestManager
20. Microsoft Asp.Net Ajax框架入门(12) 了解异步通信层
最新评论
1. re: Microsoft Asp.Net Ajax框架入门(3) 操作DOM元素
怎么操作DOM的添加和删除
--kog
2. re: 浅述WinForm多线程编程与Control.Invoke的应用
多谢,多谢,帮我解决了个问题。
--Hecate_Eos
3. re: sqlserver2005数据库还原脚本
在management studio中使用restore时,生成的脚本如下: RESTORE DATABASE IAC FILE = N'IAC' FROM DISK = 'l:\IACSyst...
--小市民
4. re: Behavior模型应用:可拖动的div容器
哥们!加油,这几篇关于ASP.NET AJAX 的我都看了,不错。
--GoodGoodStudy
阅读排行榜
1. 浅述WinForm多线程编程与Control.Invoke的应用(3584)
2. 我的WinForm App自动更新(Live Update)架构(2356)
3. Core Design Patterns(14) State 状态模式(2254)
4. 通过继承ConfigurationSection,在web.config中增加自定义配置(1900)
5. 老调重弹:插件式框架开发的一个简单应用(1806)
评论排行榜
1. 我的WinForm App自动更新(Live Update)架构(36)
2. 浅述WinForm多线程编程与Control.Invoke的应用(24)
3. Microsoft Asp.Net Ajax框架入门(7) 名称空间、类、继承、接口(10)
4. 老调重弹:插件式框架开发的一个简单应用(8)
5. Core Design Patterns(14) State 状态模式(8)