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?

    Thanks


    Brad
     
    Brad, Jun 9, 2004
    #1
    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
     
    Patrice, Jun 9, 2004
    #2
    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
    wondering
    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
    http://msdn.microsoft.com/library/en-us/dnaspp/html/urlrewriting.asp?frame=t
    rue

    Please have a look. Hope it helps. Thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], Jun 9, 2004
    #3
  4. Brad

    Brad Guest

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


    Brad
     
    Brad, Jun 9, 2004
    #4
  5. Brad

    Daddeo

    Joined:
    Aug 14, 2008
    Messages:
    1
    Likes Received:
    0
    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 = "";
    </script>
     
    Hope this helps someone else as it took me a while to find a solution from other boards out there.

    Dave
     
    Daddeo, Aug 14, 2008
    #5
  6. Brad

    jecko

    Joined:
    Jan 8, 2008
    Messages:
    3
    Likes Received:
    0
    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 !
    thanks.
     
    jecko, Apr 22, 2009
    #6
  7. Brad

    Yoginone

    Joined:
    Mar 18, 2010
    Messages:
    1
    Likes Received:
    0
    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
    #7
    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.