0

I'm very very new to asp.net, and in my tour of its features I found that if you use Server.Transfer instead of Response.Redirect then, among other things, you could preserve the URL of the original page. I created two test pages.

The first has a textbox and a button. When you click the button, the contents of the textbox are saved in the Session variable and Server.Transfer is used to load the second page. On this page there's a button and a label. When you click the button, the label gets populated with what was saved in the session variable.

The issue is, when I click the button on the second page and the label is altered, the URL changes to that of the second page. This seems a bit to defeat the purpose, so how do I go about preserving the URL?

cost
  • 4,420
  • 8
  • 48
  • 80

1 Answers1

2

Clicking the button on the second page is causing a postback and the server is showing the URL of the page you are posting back to (the second page). In effect, you have done a Response.Redirect to yourself.

I am curious as to why you want to have two separate .aspx pages behave as if they are only one. One of the major drawbacks of using Server.Transfer is the confusion it causes the user when they think they are on a new page, but the browser says otherwise; especially in bookmarking scenarios.

If you want the logic to reside in a single .aspx page, but act as two separate logical units, then I suggest you use ASP.NET Panel controls that show/hide the logic as needed and the page's code-behind can react to the necessary events (i.e. button clicks) all in one page and the URL will be the same the entire time.

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
  • I have no current reason to want this, I'm simply learning ASP.Net. I want to know how to do this in case I ever have a reason to want to do it in the future. Afterall, there must be some places where that would be useful? If not, why allow the URL to stay the same at all? – cost Jul 06 '13 at 01:24
  • Here is a similar question [Difference Between Response.Redirect And Server.Tranfer](http://stackoverflow.com/questions/6778870/difference-between-response-redirect-and-server-transfer). It gives a nice list of when you should use each approach in the accepted answer. – Karl Anderson Jul 06 '13 at 01:56