AJAX技术所提倡的无刷新回调,在原来的技术中需要写大量的JavaScript代码或使用一些AJAX框架,使得开发效率和可维护性大大降低。其实ASP.NET2.0中,已经提供了这样的接口,这就是ICallbackEventHandler。
关于ICallbackEventHandler网上已经有很多文章介绍了,这篇实为画蛇添足。

ICallbackEventHandler存在于System.Web.UI中,我们先做一个非常简单的例子来试用一下。

第一步,在VS2005中建立一个新的WEB窗件。
第二步,在ASPX中,放上一段HTML代码(如下):


1<body>
2 <form is just another parameter definition used. The value for this is passed from the client. clientErrorCallback Name of the method that is called from the CallBackManager in case of any errors.
从这个方法返回的string是:


__doCallback('__Page',arg,CallBackHandler,ctx, ErrorCallBack)

另一个重载方法是:

public string GetCallbackEventReference(
Control control, string argument,
string clientCallback, string context)

public string GetCallbackEventReference(
Control control, string argument,
string clientCallback, string context,
string clientErrorCallback)

相关文章: