Wrox Programmer Forums
|
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
 
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..
 
Old November 30th, 2010, 06:08 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
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.
 
Old November 30th, 2010, 09:51 PM
Friend of Wrox
 
Join Date: Jun 2008
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
 
Old December 1st, 2010, 03:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
The Following User Says Thank You to Imar For This Useful Post:
dstreeter (December 1st, 2010)
 
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.





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





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