Fixing postbacks while using

Last week I had done a post on how to rewrite URLs using the URLRewriter.Net component. You can read it here . Another issue that comes up while using URL rewriting in ASP.NET is the problem of postbacks. Whenever a postback occurs in the page, you find that after the postback the URL in the address bar of the browser shows your ugly URL again which you were trying so hard to hide . You can test it out here in my website (I’ll be fixing it soon though ). Go to any joke and check the URL in your browser . You will see the friendly URL. Now write down a short comment for the joke and submit the comment. After the comment is submitted, you see that the URL in the browser has changed to something like this “ShowJoke.aspx?JokeID=123″ .

Thankfully, again the the guys at URLrewriter.Net has a simple solution for us, though it took me some time to find it . Add the following code at the top of your page

<%@ Register TagPrefix="url" Namespace="Intelligencia.UrlRewriter"
Assembly="Intelligencia.UrlRewriter" %>

and then change your form tag from <asp:form runat=”server”> to <url:form runat=”server”>

If you are using master pages, you will most probably add the above lines in your master page file

Check your webpage and postbacks and URL rewriting should be working fine now !
kick it on

10 Responses to “Fixing postbacks while using”

  1. [...] Update : Also check my post on fixing postbacks while using [...]

  2. In ASP.NET 3.5 SP1, you can set the action attribute on the ASP form control is finally acknowledged so you can set it to your rewritten URL.


  3. i have a problem i made the web application,now working on security issues, i want the in the url the name of my aspx page will not appear in the adress bar……e.g http://localhost:2650/WebSite3/salaryadvance.aspx i don’t wanna show the name salaryadvance.aspx…as i also used the tree view nagvigation in my web application…..pls solve my issue….

  4. Thanks for helpful article.

  5. @Enum You will have to show some kind of URL, if you cannot show it, how will people know about your URL and come to your page.
    @Hamayun Glad that you found it helpful

  6. Hey great tip. But i seem to have a problem using the url:form tag.
    I use requiredFieldValidator control and this control fires the server event (when control are not valid) when i have changed to .

    When i cange back to it workes fine. Ant ideas or tips on this issue.


  7. Hi there,

    I have the same problem as Anders:

    When I change the server tag to <url:form
    All my validators (regularexpression, required) seem to be ignored.
    I have a button with property: CausesValidation=true

    When this button is clicked the validators ARE fired, but the page posts back anyway :S.
    When I change the tag back to the validators also work but the postback doesnt occur (just as it should work).

    Please help with this, because this tool is awesome and I want to keep using it!!! :)

  8. hi, thanks for your helpful article. realy helpful. With there be any other conflicts when using Ajax and third party controls. like above mentioned validater control issues!!


  9. Thanks , very helpfull

  10. @Anders and @John

    Try to put the code of onclick event function into

    if (Page.IsValid) {
    // your code

    It works fine