How useful an Actionless form could be

by Amit Verma on August 26, 2010

in ASP.Net

This article is relevant to ASP.NET. Knowledge of HTML and ASP.Net is required.

I was working on a project where I had to implement URL rewriting. I was also working on a tool to update a site’s (let’s say a.com) content. The tool was hosted on another domain (b.com). I had to use images and CSS (everything else was in a database) lying at a.com onto b.com to preview the changes.

Let’s see what problems I faced in both the situations and how these were solved using Actionless form. I have given similar examples, not the real situations.

Case 1: URL Rewriting

I was working on URL Rewriting where I had to work with hierarchical pages, something like below.

Page Hierarcy - How useful an Actionless form could be

So the URLs should be:

  • http://a.com/products/category1/product1.aspx
  • http://a.com/products/category1/product2.aspx
  • http://a.com/products/category1/product3.aspx
  • http://a.com/products/category2/product4.aspx and so on…

But the actual page exists at http://a.com/products/default.aspx.

There are some server controls on the page as well which raise page postback. For example, you have two dropdowns – one for categories and another for products. When you choose an item from categories dropdown it raises a postback to update the products dropdown to show relevant products.

By default, the action attribute of form is set to the actual page and the path will be relative not absolute, “default.aspx” in this case.

So now, suppose you have opened http://a.com/products/category1/product1.aspx URL and you have picked an item from category. It will raise a postback event and look for default.aspx at http://a.com/products/category1 but its not there and the page will break. If you remove action attribute from form element then it will always postback to the same page and the URL rewriting rules will take care of rest of the things.

Case 2: using one domain’s files on another domain/sub-domain

There might be cases when we have to use images and CSS lying on another domain. There are two options to achieve this – either use absolute path or use base tag. I had to opt for base tab because the IMAGE URLs were saved in the database with the running text (I know I could search and replace them using regex but I still opted for base tag).

Now, when I have used base tag, it will add a base URL to all the relative URLs and it includes the value of action attribute in form tag. Let’s name the domains, the images are at a.com and are being used on b.com. So when the postback event will be raised, it will find the action attribute file at a.com which isn’t there.

To overcome this situation, we can remove the action attribute so that it will always postback on the same page.

Solution

Unfortunately ASP.Net doesn’t give option to change or remove the value of action attribute directly. But a new form class can be implemented by inheriting System.Web.UI.HtmlControls.HtmlForm class. The implementation of Actionless form is given at this page – look for the section “Handling Postbacks”. You can also download the DLL from here.

{ 0 comments }

Plugin Update: Assign Categories to Pages – version 1.2

by Amit Verma August 15, 2010

Tweet Updates in version 1.2: Compatible with WordPress 3 Why it wasn’t working with WP3 WordPress had introduced Post Types in WP2.9. The default post types are post, page, attachment, revision, and nav-menu-item. WordPress had no restriction on applying taxonomies (category and tag) on any post type but had given the option to select for [...]

2 comments Read the full article →

Plugin: Assign Categories to Pages – version 1.1

by Amit Verma April 12, 2010

Tweet I have updated Map Categories to Pages. It has auto-insertion capability now. New Features in version 1.1: Option for auto-insertion of the Pages on Category pages Option for auto-insertion of Posts on the Pages which belong to the same category To enable the features, goto the Map Categories to Pages settings page. Choose the [...]

6 comments Read the full article →

Assign Categories to Pages in WordPress

by Amit Verma February 17, 2010

Tweet WordPress has different options for organizing posts. One of them is Categories. The categories can only be assigned to posts, not to pages in WordPress. But sometime you might want to categorize the pages as well. Here are a few cases. To display related posts on a page. To display pages and categories in [...]

18 comments Read the full article →

A few posts to share from the year 2009 and 2008

by Amit Verma December 26, 2009

Tweet I would like to share a few posts which I think are useful. Tip : Do more with Format Painter You can be a victim of phishing by blindly following a link in an email Access dictionary quickly from Apple applications on Mac Obscene comments on your blog can put you behind the bars [...]

Read the full article →

Merry Christmas and Happy New Year ’09

by Amit Verma December 25, 2009

Tweet Wishing all of you a very Happy New Year and Merry Christmas ’09. This year was full of changes and very busy for me. I was too occupied with many projects. I couldn’t even blog after June 3rd. I will try to blog regularly in the year 2010. I am also planning to include [...]

Read the full article →

Change photo capture date and time : iPhoto

by Amit Verma June 3, 2009

Tweet Clicked pictures with incorrect date and time? It become really hard to organize photos with wrong date and time. Most of the picture editing software doesn’t allow to change photo capture date but iPhoto gives a convenient way to update this information. Change date and time of only one picture Select the picture and [...]

2 comments Read the full article →

Online friends list in Orkut

by Amit Verma April 16, 2009
Orkut: Gmail online friends list

Tweet Orkut is well integrated with gmail chat. Now you may also notice “Online friends” tab in the left-bottom corner of orkut. Click on the tab to expend and see the online gmail contacts.

Read the full article →