views:

126

answers:

1

I'm trying to write an AJAX enabled WebControl. This is my first AJAX control and apart from the usual use of UpdatePanels and ScriptManagers, I've not got a lot of experience in the other angles and use of AJAX.

I've found a number of examples and projects that claim to be AJAX enabled control's, although they all seem to be missing the final step, i.e. How to actually start calling server side methods from the Client Side.

This is the example I'm currently working with: http://dotnetslackers.com/articles/ajax/ASPNETAJAXControlDevelopment.aspx

Fair enough, it shows how to extend the DOM model with some extra events... However, it never actually seems to do anything server side once it's created?

How would I go about firing off some server side methods within my control class (ImageButton.cs in that example)?

+1  A: 

Grab the source for the AjaxControlToolkit and open the AjaxControlToolkit.sln. There's 1 main project and about 40 controls for you to play with.

Some are really simple and easy to wrap your head around:

The source is written consistently across controls, both the C# and JavaScript, and commented well. They have a Base Class (ExtenderBase/ExtenderControlBase.cs) that has the majority of their "state saving" code that is re-used throughout the rest of the library.

The only thing that went over my head were some of the method attributes and code to do with Design time rendering in the Visual Studio IDE. I don't get that stuff yet.

Edit: Re server-side events, any class that implements IPostBackEventHandler (ie, RaisePostBackEvent() method) exposes custom events. For example look at the Rating control which fires a Changed event developers can subscribe to. ReorderList and Tab Container also implement custom events.

Crescent Fresh
I cant see any examples there of firing a server side method from the javascript of the AJAX control?
GenericTypeTea
Server-side event you mean?
Crescent Fresh
Any class that implements `IPostBackEventHandler` will have what you're looking for.
Crescent Fresh