RewritePath and Postbacks

Discussion in 'ASP .Net' started by Brad, Jun 9, 2004.

  1. Brad

    Brad Guest

    In a portal like application I'm using rewritepath to change from fake
    friendly urls back to a central "default" page that actually serves all of
    the urls. It works quite well, except... if the page has controls which
    cause postback the "default" url is displayed. This makes sense looking at
    the form's action which = "default.aspx" and not the fake url. So my
    quesiton is, is there a way to maintain the fake url even on postbacks?


    Brad, Jun 9, 2004
    1. Advertisements

  2. Brad

    Patrice Guest

    Not familiar with this but perhaps by using RewritePath again to restore the
    friendly name (never used URL rewriting but I belive I saw this in article)
    ??? Let us know.

    Patrice, Jun 9, 2004
    1. Advertisements

  3. Hi Brad,

    From your description, you're using UrlReWrite in ASP.NET web application
    and found that when the page is posted back , the browser's address bar
    will display the actual underlying url rather than the fake url. So you're
    how to avoid this, yes?

    Based on my research, this is a normal behavior of when we using
    UrlRewriting for some web page which perform post back. Because the page's
    <form > tag has a "action" attribute which is specified the actual url. And
    the Buildin System.Web.UI.HtmlControls.HtmlForm doesn't provide any means
    to change the action or prevent the action from being redner. However,
    there is a way to workaround this, we can define a custom Form class which
    derive from the
    System.Web.UI.HtmlControls.HtmlForm and override the RenderAttribute method
    so as to remove the "action" attribute. The following tech article in MSDN
    has mentioned this way in the "Postback handling" section:

    #URL Rewriting in ASP.NET

    Please have a look. Hope it helps. Thanks.


    Steven Cheng
    Microsoft Online Support

    Get Secure!
    (This posting is provided "AS IS", with no warranties, and confers no

    Get Preview at ASP.NET whidbey
    Steven Cheng[MSFT], Jun 9, 2004
  4. Brad

    Brad Guest

    Thank you. I think custom form class will do just what I need.

    Brad, Jun 9, 2004
  5. Brad


    Aug 14, 2008
    Likes Received:
    I struggled with this issue myself for a while when I implement Url Rewriting on a client's site. In our case, I found that the easiest way to keep postbacks from failing because of the incorrect form action was to remove the action value via javascript. For this site, all forms post to themselves anway, so removing the action value causes that behavior by default.

    I just placed the following code in the footer control (which is included on every page of the site) and it worked like a charm. We've got a form control on every page of the site, so there's never a time when it wouldn't find the form element.

    Code (Text):

    <script language="javascript">
    var theForm = document.getElementById("frmMain");
    theForm.action = "";
    Hope this helps someone else as it took me a while to find a solution from other boards out there.

    Daddeo, Aug 14, 2008
  6. Brad


    Jan 8, 2008
    Likes Received:
    Hi Daddeo, I don't often reply to posts (I'm lazy... i confess) but this time I neeeeeed to thank you sooo much. YOU ARE A GENIUS !!!!! I've been hanging on this problem for a while and your solution really got me out of it !
    jecko, Apr 22, 2009
  7. Brad


    Mar 18, 2010
    Likes Received:
    javascript code only fires 1st time

    Hi Daddeo and jecko, I tried using the javascript code above but it is only working on the 1st post back. How do I do to work on all postbacks? Does it happen to you as well?
    Yoginone, Mar 18, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.