Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 30th, 2010, 05:11 PM
Registered User
 
Join Date: Aug 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default Response.Redirect - passing parms

Hi Imar,

I'm still having a great time reading the book and trying to develop my golf club web application. The exercise in Chapter 14 that creates new PhotoAlbums then allows adding Pictures makes use of passing a newly created ID of the PhotoAlbum to the next page (ref Chap 14, p 502 in the how it works discussion).

The VB.NET code is:
Dim myPhotoAlbum As PhotoAlbum = CType(e.Entity, PhotoAlbum)
Response.Redirect(String.Format("ManagePhotoAlbum. aspx?PhotoAlbumId={0}", myPhotoAlbum.Id.ToString()))

In my application, I want to pass the Id as well as the Name to the next page. I've been trying to make this work, but apparently have not used correct syntax for passing both of these parameters. Am I missing something in order to send myPhotoAlbum.Name (in addition to the Id already shown in the example)?

Thanks.

Last edited by dstreeter; December 1st, 2010 at 08:19 AM..
Reply With Quote
  #2 (permalink)  
Old November 30th, 2010, 06:08 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You can separate parameters with an &:

String.Format("ManagePhotoAlbum.aspx?PhotoAlbumId= {0}&Name={1}", someId, someName)

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old November 30th, 2010, 06:23 PM
Registered User
 
Join Date: Aug 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Imar,

Thank you - it works great. Seems like I was using every wrong variation of this syntax.

I searched the web last night to try and get this right, but never found a great example that I understood.

Thanks again.
Reply With Quote
  #4 (permalink)  
Old November 30th, 2010, 09:51 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

But there's a *BIG* caution about doing this!

String.Format("ManagePhotoAlbum.aspx?PhotoAlbumId= {0}&Name={1}", someId, someName)

If, for example, the value of someName contains various special characters (e.g., & or = or ? or % or even space), then the value may welll *NOT* be passed correctly to the target page. And you are somewhat dependent on browser vagaries here.

So you should probably always play it safe and use Server.URLEncode with non-numeric variables/values.
Code:
String.Format("ManagePhotoAlbum.aspx?PhotoAlbumId={0}&Name={1}", _
    someId, _
    Server.UrlEncode(someName)  _
    )
I assume that someId is a number, and you would never need to UrlEncode a number.

http://msdn.microsoft.com/en-us/library/zttxte6w.aspx
Reply With Quote
  #5 (permalink)  
Old December 1st, 2010, 03:41 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yes, good suggestion from Old Pedant that will help you prevent a lot of potential problems.

In addition, you may not have to pass the name to the target page. Since the ID is unique, you could get the associated object (a PhotoAlbum in this case) based on the ID passed to the target page and then retrieve its name. Whether that is preferable depends. If you are already working with the PhotoAlbum it's any easy way to avoid cluttering the query string. However, if it means hitting the database just to get the name, it may be better to pass it through the query string. Also, depending on your site, it may also be good for search engine optimization purposes to pass the name to the target page as it provides more context about the otherwise anonymous ID. But I guess that's a topic for another day....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
dstreeter (December 1st, 2010)
  #6 (permalink)  
Old December 1st, 2010, 08:18 AM
Registered User
 
Join Date: Aug 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks to Old Pendant and Imar for the additional caution on passing the "Name" information with the redirect. Although my application would not normally call for special characters in the Golf Course name, a user could enter one by mistake.

I appreciate the quick response and great advice.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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
ddl response.redirect and passing value dorothee ASP.NET 1.0 and 1.1 Basics 0 June 11th, 2004 03:14 AM
passing a variable using response.redirect katie456 Classic ASP Databases 3 January 20th, 2004 02:35 AM
Passing date parms into a DTS pkg with dtsrun gbrockman SQL Server DTS 2 October 26th, 2003 05:54 PM
Response.Redirect dhborchardt Classic ASP Basics 4 June 16th, 2003 05:56 AM



All times are GMT -4. The time now is 07:42 PM.


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