"&" In QueryString

Discussion in 'ASP General' started by Arpan, Oct 25, 2003.

  1. Arpan

    Arpan Guest

    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=Sector 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, Oct 25, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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=Sector 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 (http://www.grisoft.com).
    Version: 6.0.525 / Virus Database: 322 - Release Date: 10/9/2003
    Mohamed Hosam, Oct 25, 2003
    #2
    1. Advertising

  3. > 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], Oct 25, 2003
    #3
  4. Arpan

    Arpan Guest

    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]" <> wrote in message
    news:...
    > > 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, Oct 25, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. suzy
    Replies:
    3
    Views:
    3,084
  2. Axel Dahmen

    Pack QueryString

    Axel Dahmen, Jun 29, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    533
    Axel Dahmen
    Jun 29, 2003
  3. Natty Gur

    Re: Pack QueryString

    Natty Gur, Jun 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    495
    Natty Gur
    Jun 29, 2003
  4. Mehdi
    Replies:
    6
    Views:
    36,094
    sloan
    Apr 6, 2006
  5. Adeel Ahmad
    Replies:
    1
    Views:
    423
    Anthony Jones
    Mar 7, 2006
Loading...

Share This Page