Monday, March 26, 2012

Exposing methods in ASP.NET AJAX Control Project

I've read every bit of documentation that I could find online (which isn't a lot) about creating your own extender with the ASP.NET AJAX Control Project. There are lots of examples about how you expose the properties in the Extender.vb or Extender.cs file, which passes the values down to the .js file. But is it possible to expose callable methods? I can add handlers forevents, but what about methods you can call at any time?

If anyone can give me an example of the proper syntax to do this, it would be greatly appreciated. Thanks.

You can't expose methods from the .cs or .vb file of your control; you'll need to use webservices or pagemethods to call a server method.

I don't want to call a server method, I want to expose a function in the Behavior.js.


Do you mean callable by JavaScript or Server-Side Code ?

all methods in your behavior.js in the Prototype section are callable methods.

You can call methods using the

$find(BehaviorID).Method() notation


Thank you for the response. That's what I needed, but just out of curiosity, is it possible to "expose" those methods to the servers side... much in the same way that the properties in the extender.cs file exposes the properties in the behavior.js file?


No.

The properties in the .cs file will be injected into the output html, and some initialization logic implemented in javascript is responsible for initializing the component with those properties.

Basically, server side object and client side object can't access each other directly.

No comments:

Post a Comment