my6solutions

asp .net, the social web & other distractions

 

Running Apps


PayPal - The safer, easier way to pay online!

Disclaimer

I am in no way affiliated with Microsoft or Google. I am just another developer trying to make a difference. All opinions and observations are usually my own.

Running Ajax.NET Professional (AjaxPro) under ASP .NET MVC

Note: With ASP .NET MVC, jQuery is the more convenient method you could use to make Ajax calls.

Ajax.NET is the first Ajax library for the .NET framework. Up until the day ASP .NET 3.5 was released, there was nothing quite like it. In ASP .NET 2.0, the UpdatePanel was introduced as a way to enable partial rendering on ASP .NET pages. UpdatePanels are quick to implement. However, the downside of it is its inefficiency. The viewstate of the page gets posted back as well! This gives you a bloated asynchronous request and basically defeats the purpose.

It is during times like this that Ajax .NET looks very attractive. With support for PageMethods in ASP .NET 2.0 (in Ajax.NET the attribute tag [AjaxMethod] is used instead), JSON serializers, built-in caching, javascript compression, synchronous calls, etc. what is there not to like about Ajax .NET. You could even return DataTables, DataSets, enums, and other custom structures to the client-side directly.

It is also an open source project and the code is available here. Unfortunately, development of Ajax.NET has "stopped", and the creator himself has suggested the use of the Ajax features provided by ASP .NET 3.5. However, the project itself is still being updated once in awhile. I guess it's hard to completely let go of a project that you've been working on for a long time. People just get attached to their code. Well... I know I do.

Anyway, I have been using Ajax.NET since .NET 2.0, as well as since .NET 3.5. I haven't found a good reason to switch and it even runs under ASP .NET MVC and I reckon it is still better than using Ajax.ActionLink(). Unless of course, there's some easier method that I do not know of then please feel free to enlighten me anytime. Most of my Ajax use centers around requesting data from the server asynchronously and then using javascript to update the DOM.

Installing Ajax.NET

To include Ajax.NET into your MVC project, follow the following steps:

  1. Go http://ajaxpro.codeplex.com and download the latest release, i.e., 9.2.17.1 
  2. Extract AjaxPro.2.dll somewhere safe so that we can add a reference to it late in our MVC project. The other files are for the JSON serializer and for use under ASP .NET 1.1. The web.config in the zip file gives you a bunch of configurable options.
  3. Then from VS, add a reference to it in your project. 
  4. In your web.config, add the following
  5. Under <configSections>

     

       12 <sectionGroup name="ajaxNet">

       13             <section name="ajaxSettings" type="AjaxPro.AjaxSettingsSectionHandler,AjaxPro.2" requirePermission="false" restartOnExternalChanges="true"/>

       14         </sectionGroup>


    Under <configuration>

     

       30 <ajaxNet>

       31         <ajaxSettings>

       32             <token enabled="true" sitePassword="notmypassword" />

       33         </ajaxSettings>

       34     </ajaxNet>

    Under <httpHandlers>

     

      107 <add verb="*" path="/ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>

     

  6. In global.asax, you will then need to add the following line to your RegisterRoutes() method to allow AjaxPro to handle requests directed at it.

   30 routes.IgnoreRoute("ajaxpro/{*pathInfo}");


Using Ajax.NET

To be able to call your class methods on the client-side, you will need to add the [AjaxPro.AjaxMethod] attribute to the method. The AjaxMethod attribute can be used on any methods in any classes and is not limited to methods in the code-behind of your webpages. You will then need to inform AjaxPro parse the class containing your marked method to generate proxy classes for the client-side. This usually is done via the method

 

AjaxPro.Utility.RegisterTypeForAjax(Type t)

 

at the Page class. The other method is to directlypoint AjaxPro to the location by adding the script tag

 

<script type="text/javascript" src="/ajaxpro/className,assemblyName.ashx"></script>

 

The className MUST include it's namespace. Basically the above allows AjaxPro to find the method through reflection in the assembly to generate the appropriate proxy classes.

As there is not really a concept of pages in ASP .NET MVC, the second method is used and you will additionally need to add the following script tags (these are normally generated when you use RegisterTypeForAjax)

 

<script type="text/javascript" src="/ajaxpro/prototype.ashx"></script>

<script type="text/javascript" src="/ajaxpro/core.ashx"></script>

<script type="text/javascript" src="/ajaxpro/converter.ashx"></script>

And that should be all that needs to be done. If you want to know more about AjaxPro, you can visit its webpage at http://www.ajaxpro.info/. There is also an entry on how to use AjaxPro with jquery here.

 

 

Bookmark and Share

Permalink | Comments (10) | Post RSSRSS comment feed

Comments

Community Blogs

Wednesday, March 25, 2009 5:19 AM

trackback

Trackback from Community Blogs

Ajax.NET Professional and ASP.NET MVC

ASPInsiders

Wednesday, March 25, 2009 6:12 AM

trackback

Trackback from ASPInsiders

Ajax.NET Professional and ASP.NET MVC

9efish developer kigg

Wednesday, March 25, 2009 6:33 AM

trackback

Trackback from 9efish developer kigg

Running Ajax.NET Professional (AjaxPro) under ASP .NET MVC

Web Development Community

Wednesday, March 25, 2009 9:02 PM

trackback

Trackback from Web Development Community

Running Ajax.NET Professional (AjaxPro) under ASP .NET

Ioannis Karamitros

Tuesday, April 14, 2009 10:03 PM

Ioannis Karamitros

Hi all, I did not found the method RegisterRoute() at my global.asax. Can anyone help me?
Thanks

Admin

Wednesday, April 15, 2009 4:39 AM

Admin

Sorry, it should be

public static void RegisterRoutes(RouteCollection routes);

This is called from Application_Start() and it should have been created automatically when you start a new MVC project.

Admin

Wednesday, April 15, 2009 10:59 PM

Admin

well, it's ok. Gets the job done. Not too much nice themes out there but then again I didn't search for too long. Just wanted something presentable. Although, you might like to have a look at dasBlog.

Jimmy

Saturday, April 25, 2009 7:19 AM

Jimmy

THEY NEED TO SOMEHOW INTEGRATE JQUERY AS THE JAVASCRIPT FRAMEWORK. Since jquery is soo widely use for UI and also ajax, wouldnt it be better to dump prototype and have jquery.

Admin

Saturday, April 25, 2009 11:04 PM

Admin

Actually, jquery IS integrated with ASP .NET MVC now. I'm not too familiar with prototype but probably it's a matter of individual preferences. And if I'm not mistaken, prototype has been around for awhile so there would be a number of sites out there that people will still need to maintain. I think Facebook is using it or was initially using it.

SEO

Thursday, October 22, 2009 3:19 PM

SEO

You can download the latest beta of the AjaxPro library at www.ajaxpro.info/download/jQueryAjaxPro.zip.