Mark Norgate
Mark Norgate

Reputation: 51

<form> action when using Server.Transfer()

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

Upvotes: 0

Views: 990

Answers (3)

Mark Norgate
Mark Norgate

Reputation: 51

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

Upvotes: 1

Stephen M. Redd
Stephen M. Redd

Reputation: 5428

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.

Upvotes: 0

Chris
Chris

Reputation: 2045

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.

Upvotes: 0

Related Questions