views:

81

answers:

3

Hello

I am using Server.Transfer() to transfer processing from one page to another. The problem is that the form action in the source of the page, having been transferred, refers to the destination page and not the original page as per the URL in the browser.

Is there a way to make the action of the form reflect the URL in the browser, rather than the actual destination page?

Thanks in advance!

Mark

A: 

if you give the form an id you might be able to change the action in the attributes property.

<form runat="server" id="form1" action="">
</form>

and then in the code refer to the form like this:

form1.Attributes["action"] = "new action";

changing the action will probably cause postback events intended for the new page to work incorrectly. Your other alternative if your design permits would be to use the Response.Redirect.

Also, you might want to look into PostBackUrl for the buttons on the new page, which will change the page that they post to.

Chris
A: 

You should investigate if HttpContext.RewritePath might be useful here. Typically in cases like this you would use rewrite path on the PreRender event of the destination page using the URL of the original page. This causes controls that use the current internal path to generate URLs and such to "think" they are still on the original URL at the time they render themselves.

Stephen M. Redd
Hmm. I tried ReritePath in my destination page—that is, the page with the unfriendly URL—but it has no effect. The action tag in the form is still showing the unfriendly URL.Any suggestions?
Mark Norgate
+1  A: 

Not to worry, I've rewritten my routing code using the System.Web.Routing namespace so all the logic is centralised in my global.asax. Works a treat!

Thanks for your help.

Mark

Mark Norgate