Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 5th, 2010, 06:51 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default How to use PostBackUrl in pages that currently rely on Response.Redirect (heavily)?

I am changing some existing ASP.Net pages. Those pages heavily rely on Response.Redirect. Now I need to carry data between pages, and one obvious option is to change each Response.Redirect to Server.Transfer. This way the modification is very straightforward. However the problem is that Server.Transfer does not change the URL in the address bar, which some see as a problem.

The other option is to rely on PostBackUrl, but the modification seems to be extensive in some cases. For example, say I have two pages P1 and P2, both lead to page P3. P1 has a button B1. In the existing code, when B1 is clicked, it executes a chunk of code (C1) and in the end of C1, it does Response.Redirect. Same with P2, which has a button B2 and only calls Response.Redirect after a major chunk of code (C2) is executed.

Now, if I set PostBackUrl for both B1 and B2 to P3. Where is the best new home for C1 and C2 to reside?
 
Old May 5th, 2010, 09:39 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

If I follow you, I would say the place to put C1 and C2 is in the code-behind of P3. Them in the OnLoad of P3, you can detect the PreviousPageUrl and run whatever chunk of code you want based on that.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old May 5th, 2010, 10:44 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

Thanks for your reply!

I thought the same way and that's what I feared - this way, code is a bit messier than what I would like...

Another obvious option is to carry the data as URL parameters. The data I want to carry are of simple scalar types and there are only couple of them, so there is not much trouble to do it this way. The pros are:
1) The code change is very small, and I don't even need to touch those Response.Redirect;
2) Obviously URL's are all correct (since I am not using Server.Transfer)

I initially didn't like this query string solution, since it exposes more information than necessary (and in a obvious way). However that piece of information is not sensitive any way.





Similar Threads
Thread Thread Starter Forum Replies Last Post
response.redirect sarah lee ASP.NET 1.0 and 1.1 Basics 1 October 27th, 2006 08:57 AM
response.redirect ava_h .NET Framework 2.0 0 October 18th, 2006 10:21 PM
response.redirect crmpicco Classic ASP Basics 3 February 9th, 2005 01:50 AM
What is an alternative for Response.Redirect pcshan Classic ASP Basics 3 April 28th, 2004 02:10 PM
Response.Redirect dhborchardt Classic ASP Basics 4 June 16th, 2003 05:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.