当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET 2.0当中的Call Back机制

ASP.NET
Web服务器控件:LinkButton控件
Web服务器控件:ListBox控件
Web服务器控件:ListItem控件
Web服务器控件:Literal控件
Web服务器控件:Panel控件
Web服务器控件:PlaceHolder控件
Web服务器控件:RadioButton控件
Web服务器控件:RadioButtonList控件
Web服务器控件:BulletedList控件
Web服务器控件:Style控件
Web服务器控件:Table控件
Web服务器控件:TableCell控件
Web服务器控件:TableRow控件
Web服务器控件:TextBox控件
Web服务器控件:XML控件
Validation服务器控件:CompareValidator控件
Validation服务器控件:CustomValidator控件
Validation服务器控件:RangeValidator控件
Validation服务器控件:RegularExpressionValidator控件
Validation服务器控件:RequiredFieldValidator控件

ASP.NET 2.0当中的Call Back机制


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 176 ::
收藏到网摘: n/a

用过ASP.NET 2.0当中的新功能Call Back的朋友们可能会发现:ASP.NET AJAX当中的非同步Web Services调用很麻烦,还要多建立一个Web Sevices(.asmx)页面,如果您嫌额外建立一个.asmx的Web Services页面太过麻烦,今天就来介绍另一种更简易的方式可以进行非同步的调用,我们称之为Page Method。

您可以建立一个.aspx页面,并一样布置ScriptManager、TextBox与Html Button:

 

接着我们键入下面的代码:

 

接着,请测试运行的结果,您会发现一样可以通过非同步的方式调用(按下Button之后不换页就可以利用伺服器端的信息更新TextBox内容),但是不需要额外建立了一个.asmx文件,在程序的结构上稍为清爽一点了。这就是PageMethod的使用方式,请注意其中务必将.aspx的 PageMethod声明为静态方法(加上shared关键字),并且加上下面的Attribute(第1-2行):

 

同时间在.aspx页面上的ScriptManager控件,一定要将其EnablePageMethods属性设为true,才可正确使用PageMethod。