Results 1 to 5 of 5

Thread: [RESOLVED] Using the ampersand (&) symbol with Request.Querystring

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2008
    Location
    Scotland
    Posts
    68

    Resolved [RESOLVED] Using the ampersand (&) symbol with Request.Querystring

    Good afternoon

    I wonder if anyone can help me with a brain-teaser I've got. I have a database full of organisation details (names, addresses, geographical mappings etc) which I've written a fairly comprehensive Classic ASP front-end system for. The majority of drop-down lists within the search page of that system pass integer values to the back-end database which works without incident because the back-end database has been structured in that way. Similarly, the text fields pass text strings to the back-end database and that works without incident also.

    My problem though is this: I have one drop-down list whose values are populated by means of a stored procedure querying a column in a table and grouping the contents of that table: unlike the other drop-down lists there is no corresponding ID value. This works for most of the contents of that column, except where the value in the column contains an ampersand (&) character. The actual population of the drop-down list works flawlessly, but the presence of the ampersand causes major issues when it comes to accepting the selected value of that list when doing a "Request.QueryString".

    So, I have the following scenario:
    1. When I get to the drop-down list that I've described, I set the value as Barking & Dagenham;
    2. When I click the Search button, the URL that gets passed goes as http://glaweb1/doh_signposting/perfo...Submit1=Search - you can see that the space on either side of the ampersand has been replaced with a + and the ampersand itself has been replaced with %26;
    3. When I run the Request.QueryString command and display it's subsequent assignment on-screen, it displays as Barking , with a trailing space at the end of it;

    The page that contains the search criteria fields is using the "get" form method, but I need to know how I get around this so that the ampersand will be recognised as an ampersand by the next page. I don't have many options in terms of being able to alter the back-end data. I'm also constrained by the fact that the pages are currently live within the business. However, as you can probably imagine I have quite a serious need to get this issue resolved.

    Thanks in advance



    Ian Henderson

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Using the ampersand (&) symbol with Request.Querystring

    before sending data through a query string, it needs to be URL encoded... %26 is the URL encoding value for the &... %20 is the space... so what you're seeing in the link is "normal"... I'd expect to see Barking%20%26%20Dagenham ... the use of + suggests that maybe it's sending it as two values - such as if I were to search for VB forum in Google, it translates it into VB+forums ... making it two terms... as opposed to "VB Forums" or VB%20forums ... which is a single term... how are you URL Encoding your string before sending it... if the response to that question "URL wha?" then the answer is you aren't and that maybe the issue.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2008
    Location
    Scotland
    Posts
    68

    Re: Using the ampersand (&) symbol with Request.Querystring

    Hi techgnome.

    This is where I start to come apart a little bit. I don't know how to go about encoding the string that's being sent. To put you fully in the picture, I've pretty much taught myself the ASP that I've written. I was of the understanding that when you use the "get" form method and specify a page in the action, the selected value of every control within that method is then available on the specified page. Therefore, how do I do any sort of encoding on the "free-text" controls and combo's such as this one?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Using the ampersand (&) symbol with Request.Querystring

    Ah... that wasn't clear... I thought you were sending the querystring by "Hand" ... didn't realize it was from a form submission... At any rate, don't use the querystring... use the forms collection instead.
    http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx

    It'll contain the unencoded values passed by the get.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2008
    Location
    Scotland
    Posts
    68

    Re: Using the ampersand (&) symbol with Request.Querystring

    You are a legend. I've changed the form method from a "get" to a "post" and replaced the Request.QueryString for Request.Form. Because the offending value was also being passed to a subsequent page as a parameter, I've dropped in a Server.HTMLEncode which is working an absolute treat. My most profound thanks for your help, and my very best wishes to you and yours for the festive season.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width