escaping quotes

Discussion in 'ASP General' started by Mike P, Nov 11, 2008.

  1. Mike P

    Mike P Guest

    Can anybody tell me what is wrong with this code? I am thinking it is
    something to do with how I am escaping the quotes.

    <img src="pix2.asp?lbmid=" & Request.QueryString("LBMID") & "&LBMEmail="
    & Request.QueryString("LBMEmail") & """ width=1 height=1 border=0>



    *** Sent via Developersdex http://www.developersdex.com ***
     
    Mike P, Nov 11, 2008
    #1
    1. Advertising

  2. Mike P wrote:
    > Can anybody tell me what is wrong with this code? I am thinking it is
    > something to do with how I am escaping the quotes.
    >
    > <img src="pix2.asp?lbmid=" & Request.QueryString("LBMID") &
    > "&LBMEmail=" & Request.QueryString("LBMEmail") & """ width=1
    > height=1 border=0>
    >
    >
    >

    Two things:
    You failed to delineate the server-side code from the client-side html.
    Why are you trying to inject a quote there at the end?

    Actually 3 things:
    You failed to describe your symptoms. At least view the page source after
    running the page and show us the resulting img tag, or tell us what the
    error message is.

    Anyways, the long version:

    <img src="pix2.asp?lbmid="
    <%Response.Write Request.QueryString("LBMID") %>
    &LBMEmail=
    <%Response.Write Request.QueryString("LBMEmail") %>
    " width=1 height=1 border=0>

    The shortcut that most people use:

    <img src="pix2.asp?lbmid="<%=Request.QueryString("LBMID")%>
    &LBMEmail=<%=Request.QueryString("LBMEmail")%>" width=1 height=1 border=0>

    The idea is to write the html the way it should look with hard-coded values:

    <img src="pix2.asp?lbmid=12345&LBMEmail=" width=1 height=1
    border=0>

    Then replace the hard-coded values with the server-side script blocks. There
    is no need to do the concatenation inside the server-script blocks. Yes, you
    could have done this:

    <img src="pix2.asp?lbmid="<%=Request.QueryString("LBMID") & "&LBMEmail=" &
    Request.QueryString("LBMEmail")%>" width=1 height=1 border=0>

    but it can get confusing and there really is no need to do this unless you
    are making decisions in the server-side code as to what name-value pairs are
    being included in the querystring.

    --
    Microsoft MVP - ASP/ASP.NET - 2004-2007
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Nov 11, 2008
    #2
    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. Lawrence Tierney

    Multiline quotes - escaping quotes - et al

    Lawrence Tierney, Dec 24, 2003, in forum: Java
    Replies:
    3
    Views:
    4,544
    Andrew Thompson
    Dec 24, 2003
  2. DartmanX
    Replies:
    1
    Views:
    3,492
    Chris Smith
    Jan 23, 2005
  3. John Salerno

    escaping quotes

    John Salerno, Feb 28, 2006, in forum: Python
    Replies:
    2
    Views:
    362
    John Salerno
    Feb 28, 2006
  4. cesco

    escaping only double quotes

    cesco, Aug 31, 2007, in forum: Python
    Replies:
    2
    Views:
    282
    iapain
    Aug 31, 2007
  5. Replies:
    7
    Views:
    196
    Thomas 'PointedEars' Lahn
    May 17, 2005
Loading...

Share This Page