博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

.NET ComponentArt 客户端调用服务器端函数

Posted on 2008-02-19 15:16  孤峰皓月  阅读(1504)  评论(0编辑  收藏  举报
    今天碰到的事情比较晕,我的服务器端的方法名与客户端的方法名定义成一样的了,后来点击链接,就是会出现“堆栈溢出”,网上找了一下,好像人家也没有遇到这个问题,后来仔细看了一下,发现可能是名称相同导致的,所以马上改了一下名称,结果又出现“缺少对象”这一错误。
    后来网上查了一下资料,原来在WEB.Config文件里面应该还要加上一句
  <httpHandlers>
    <add type="ComponentArt.Web.UI.CallbackHandler,ComponentArt.Web.UI" path="*.aspx" verb="*" />
  </httpHandlers>

后台:
 [ComponentArtCallbackMethod]
  public string GetServerDateString()
  {
    return DateTime.Now.Date.ToString("MMMM dd, yyyy");
  }

前台:
alert(GetServerDateString());

具体可以参考页面:http://www.componentart.com/forums/ShowPost.aspx?PostID=16637

ComponentArt CallBack 2006.1
Posted: 2/23/2006 12:37:47 PM
By:  miljan

Here is a brief overview of the new features and improvements of the ComponentArt CallBack control for the Web.UI 2006.1 release. Our goal was to address common customer feature requests and make our callback framework more comprehensive.

Viewstate Maintenance

Starting with the 2006.1 release, you will be able to access the latest state of ASP.NET controls contained on the page from your callback event handler. To enable this feature, simply set the PostState CallBack property to true.

Passing Multiple Parameters From the CallBack.Callback() Client-side Method

We now support passing any number of simple-type parameters from the CallBack.Callback() call:

  CallBack1.Callback('Stephen', 'Hatcher', 30, true);
                

These parameters will be available in the new string collection event args member "Parameters":

  string firstName = e.Parameters[0];
                string lastName = e.Parameters[1];
                int age = Convert.ToInt32(e.Parameters[2]);
                bool isManager = Convert.ToBoolean(e.Parameters[3]);
                

Bypassing Page Life Cycle

We have noticed that many of our customers have been using 3rd party AJAX libraries side-by-side with our CallBack control in order to be able to send quick commands to the server without going through the page life cycle. This was a way to efficiently execute server-side logic when complex rendering through callbacks was not needed. We now provide this functionality out of the box through a custom HTTP handler. To take advantage of it, do the following:

1. Specify the HTTP handler within the <system.web> section of your web.config file:

  <httpHandlers>
                    <add type="ComponentArt.Web.UI.CallbackHandler,ComponentArt.Web.UI" path="*.aspx" verb="*" />
                  </httpHandlers>
                

2. Mark all server-side methods you wish to expose on the client with the [ComponentArtCallbackMethod] attribute. For example:

  [ComponentArtCallbackMethod]
                public string GetServerDateString()
                {
                return DateTime.Now.Date.ToString("MMMM dd, yyyy");
                }
                

or

  [ComponentArtCallbackMethod]
                public int ServerSideAdd(int number1, int number2)
                {
                return number1 + number2;
                }
                

NOTE: You can have any number of simple-type arguments within the function signature.

3. You can then access those methods directly from your client-side JS code:

  alert(GetServerDateString());
                

or

  alert('Server side: 2 + 2 = ' + ServerSideAdd(2, 2)); 

Automatic Refresh

Automatic callback refresh can be enabled by setting the RefreshInterval property to the desired time interval (in milliseconds). You can use the client-side API to change the parameter(s) that are being sent to the server at any given time.

We hope that you will enjoy the new features of ComponentArt CallBack 2006.1.

The ComponentArt Team
Helping You Build Something Amazing