RewritePath and Postbacks

B

Brad

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
 
P

Patrice

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
 
S

Steven Cheng[MSFT]

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
 
Joined
Aug 14, 2008
Messages
1
Reaction score
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:
<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
 
Joined
Jan 8, 2008
Messages
3
Reaction score
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.
 
Joined
Mar 18, 2010
Messages
1
Reaction score
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?
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top