Space is removed between the two ASP expression codes

I am new to ASP and have been instructed to update a file by a client. When I try to "track" two variables with a space between them, the space is removed. Any ideas why?

Here are two examples:

<%
    Dim variable1, variable2
    variable1 = "Hello"
    variable2 = "there"
%>
<p><%= variable1 %> <%= variable2 %></p>

      

or

<p><% Response.write( variable1 ) %> <%= Response.write( variable2 ) %></p>

      

This writes: <p>Hellothere</p>

no space between two words. Am I doing something wrong? or is it ok for ASP?

I've resorted to using the following, but I find it hard to believe that content outside <%%> will be removed.

<% Response.Write( variable1 & " " & variable2 ) %>

      

Any help would be appreciated.

+3


source to share


1 answer


Uh-huh. This is one of those things. Spaces before or after code blocks ( <%...%>

) are considered part of the HTML document, but spaces between successive code blocks are ignored. You have several options:



  • Insert &nbsp;

    Between (Explicit Space):

    <p><%= variable1 %>&nbsp;<%= variable2 %></p>
    
          

  • Write a complete tag in one ASP context:

    Response.Write "<p>" & variable1 & " " & variable2 & "</p>"
    ' or
    <p><%= variable1 & " " & variable2 %></p>
    
          

+2


source







All Articles