Ask a Question related to ASP, Design and Development.

  1. #1

    Default "&" In QueryString

    A link has the following URL:

    <a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%=
    Request.QueryString("cadd1") %>&cadd2=<%= Request.QueryString("cadd2")
    %>&cplace=<%= Request.QueryString("cplace") %>">Click</a>

    Suppose the names in the above querystring have the following values:

    cname="Danny"
    cadd1="House 97"
    cadd2="Sector 3 & 4"
    cplace="Timbaktoo"

    Becuase of the presence of an ampersand (&) in the value of cadd2 (between 3
    and 4), the next page doesn't get the correct querystring. The querystring
    carried forward to the next page looks something like this:

    Page1.asp?cname=Danny&cadd1=House%2097&cadd2=Secto r 3

    That's it!!! Now how do I ensure that the presence of ampersand in any value
    of the querystring doesn't affect the querystring in any way & the next page
    gets the correct querystring? I even tried using Server.URLEncode but that
    didn't make any difference.

    Thanks,

    Arpan


    Arpan Guest

  2. Similar Questions and Discussions

    1. [ASP/VBscript] Preserve querystring in "get" form ?
      Maybe a stupid question, but how can I preserve an existing querystring when using the "get" method to process the form. When using "post" the...
    2. CFINPUT type="radio" w/ "value" requires "label"
      On a Flash form, when you specify type='radio' and value='whatever', the value of the 'value' attribute will be displayed as a label if no 'label'...
    3. querystring problem after using header("Location:xxx")
      On "page1.php?aaa=1" I do a redirect to remove the variables in the querystring that I don't need anymore: header("Location: page1.php?bbb=1") ;...
    4. Request.Form("Field Name") Versus Request.QueryString("Field Name")
      I want to know what's the differences between Request.Form("Field Name") and Request.QueryString("Field Name") OR they function exactly the...
    5. "Start" "Program" "Menu" list is empty
      For what ever reason my list of installed programs in my "Start" "Programs" menu is empty. Anyone know how to restore the list. Thanks for your...
  3. #2

    Default Re: "&" In QueryString

    An easy way is to replace it with anything then replace that thing with it
    again when you receive it.

    For example:

    <%
    cadd2 = Replace(cadd2, "&", "zxc")
    %>
    <a href=page1.asp?cadd2=<%=cadd2%>&...>Click</a>

    When you receive it,

    <%
    cadd2 = Replace(Request.QueryString("cadd2"), "zxc", "&")
    %>

    Mohamed

    "Arpan" <arpan_de@hotmail.com> wrote in message
    news:upW0vfomDHA.2772@TK2MSFTNGP12.phx.gbl...
    > A link has the following URL:
    >
    > <a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%=
    > Request.QueryString("cadd1") %>&cadd2=<%= Request.QueryString("cadd2")
    > %>&cplace=<%= Request.QueryString("cplace") %>">Click</a>
    >
    > Suppose the names in the above querystring have the following values:
    >
    > cname="Danny"
    > cadd1="House 97"
    > cadd2="Sector 3 & 4"
    > cplace="Timbaktoo"
    >
    > Becuase of the presence of an ampersand (&) in the value of cadd2 (between
    3
    > and 4), the next page doesn't get the correct querystring. The querystring
    > carried forward to the next page looks something like this:
    >
    > Page1.asp?cname=Danny&cadd1=House%2097&cadd2=Secto r 3
    >
    > That's it!!! Now how do I ensure that the presence of ampersand in any
    value
    > of the querystring doesn't affect the querystring in any way & the next
    page
    > gets the correct querystring? I even tried using Server.URLEncode but that
    > didn't make any difference.
    >
    > Thanks,
    >
    > Arpan
    >
    >

    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    Version: 6.0.525 / Virus Database: 322 - Release Date: 10/9/2003


    Mohamed Hosam Guest

  4. #3

    Default Re: "&" In QueryString

    > gets the correct querystring? I even tried using Server.URLEncode but that
    > didn't make any difference.
    Can you show the code you used, and how it "didn't make any difference"?
    Server.URLEncode should encode your spaces and special characters so that
    they are passed correctly in the URL and are fully recoverable by the
    receiving page.


    Aaron Bertrand [MVP] Guest

  5. #4

    Default Re: "&" In QueryString

    Thanks Aaron. Actually I had to re-model the application where in a user
    clicks a link in Page1.asp (href of the link along with the entire
    querystring being the same as what I had provided in my first question). Due
    to some reasons, I am assigning the href of the link in Page1.asp using
    JavaScript (though it could have been done using ASP as well). Assume that
    clicking this link takes the user to Page2.asp. In the JavaScript code in
    Page1.asp (which directs the user to Page2.asp), I have used the function
    decodeURI so that the ampersand existing within a value in the querystring
    gets passed on to Page2.asp. As expected, Page2.asp gets the querystring in
    the correct format. The querystring looks something like this:

    ?cname=Danny&cadd1=House 97&cadd2=Sector 3 & 4&cplace=Timbaktoo

    Page2.asp has another link, clicking which the user is taken back to
    Page1.asp along with the entire querystring. This is the code which creates
    the link (note that I have encompassed the value of cadd2 in
    Server.URLEncode()):

    <a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%=
    Request.QueryString("cadd1") %>&cadd2=<%=
    Server.URLEncode(Request.QueryString("cadd2") %>&cplace=<%=
    Request.QueryString("cplace") %>

    But when the user goes back to Page1.asp, the querystring in Page1.asp looks
    like this:

    ?cname=Danny&cadd1=House+97&cadd2=Sector+3+&cplace =Timbaktoo

    Please note that in the value of cadd2, the characters "& 4" have been
    neglected. I hope I have taken the right approach. Could you please try to
    sort out this problem?

    Thanks,

    Regards,

    Arpan


    "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    news:uQp61apmDHA.372@TK2MSFTNGP11.phx.gbl...
    > > gets the correct querystring? I even tried using Server.URLEncode but
    that
    > > didn't make any difference.
    >
    > Can you show the code you used, and how it "didn't make any difference"?
    > Server.URLEncode should encode your spaces and special characters so that
    > they are passed correctly in the URL and are fully recoverable by the
    > receiving page.
    >
    >

    Arpan Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139