Introduction
Anthem Ajax is one of the best Ajax libraries available to write Ajax without writing JavaScript in ASP.NET. But attempting to combine it with Extensionless URL ReWriting is quite a challenge.
You can download Anthem Ajax from here. You can read more about the URL ReWriting Tool used from here.
The Form control used is an extension of this article.
Background
In the current web development scenario, the two most desirable goodies are:
- Ajax: giving no postbacks, and
UrlReWriting
: Giving SEO friendly, beautiful URLs
But it has been quite difficult to use both of them together.
The Ajax breaks down whenever there is URL of the form: http://foo.com/id/151. To overcome this problem, I tackled it with a strategy to provide different views of the same URL to the HTML form and to the Ajax Framework.
The Solution
Towards uniting Anthem Ajax with smooth URLs, my strategy was to provide different views of the same URL to the HTML form and to the Ajax Framework. I wanted the action attribute of the form to have the original RawUrl
as its value. While I wanted the Anthem Ajax framework to have the ReWritten Simple URL as its value.
I created a new Form
Class by inheriting it from HtmlForm
Class. Then I wrote the original URL (URL without ReWriting) in the name attribute of the form. And in the action Attribute, the Raw URL (beautiful Url, as it appears in the Address Bar).
Then, I made one change in the anthem.js file of the Anthem Download. I made the function Anthem_GetCallBackUrl
return URL from form.name
instead of form.action
.
This solves the two problems:
- The
Action
attribute of the form will have the original beautiful Extensionless URL (Raw URL).
This will help to preserve the beautiful Extensionless URL even after page PostBacks (like those caused by button clicks). - While the Name Attribute will have the ReWritten Real URL.
This will be supplied to the Anthem Framework, making it believe that it is working without any URL ReWriting :-)
Using the Code
To see a live demo, simply run the attached sample website.
To do URL ReWriting in a project:
- Just include the DLLs in the Folder: ReWriting DLLs
- Use the Anthem Library (the DLL in the above folder) contained with this project.
- Make your Web.Config as shown in the attached Web.Config file.
- Instead of using the
form
tags in the .aspx files, use the inherited form's tags.
History
- 24th March, 2008: Initial version