 |
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 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
|
|
|
|
|

November 30th, 2010, 05:11 PM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
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..
|
|

November 30th, 2010, 06:08 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You can separate parameters with an &:
String.Format("ManagePhotoAlbum.aspx?PhotoAlbumId= {0}&Name={1}", someId, someName)
Hope this helps,
Imar
|
|

November 30th, 2010, 06:23 PM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
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.
|
|

November 30th, 2010, 09:51 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
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
|
|

December 1st, 2010, 03:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

December 1st, 2010, 08:18 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |
|