Remove empty line created from asp code in html

If in a Classic ASP page I write:

<!DOCTYPE html>

in the page source code I'll have a blank line before <!DOCTYPE html>.

How can I remove it? I new that I can write all in a single line like this:

<%pippa="Camilla"%><!DOCTYPE html>

but seems quite weird in the rest of the code. There is any way to solve it? And if yes, is it possible to use a solution in the web.config ?

What about using Dynamic Content Compression ?


This is one of the cruxes of server side code generation, the ASP processor only processes ASP code (code inside the in-line code blocks <% %>).

This means that any other HTML is left "as is" including special characters like carriage return and linefeed.

So when ASP processes your page it sees

<!DOCTYPE html>

⏎ Denotes Carriage Return, LineFeed

So as you already state in the question the only way to avoid this is placing the in-line code block on the same line.

<% pippa="Camilla" %><!DOCTYPE html>

The other approach is to break your HTML and your code assignment into different sections. I usually do this by placing my HTML inside it's own Sub / Function and pass or assign variables earlier in the page using an Init() Function, you still find yourself dealing with code like this though;

Sub DisplayHTML()
%><!DOCTYPE html>
</html><% End Sub %>

Which isn't pretty, so I tend to ignore trailing new lines unless it's affecting the rendering of the page (IE compatibility mode etc).

Another way of dealing with HTML inside your code is to build HTML templates to load the HTML and replace values defined by place-holders.

See How to edit the html from ASP in a better way?

You can't remove it. When the code is run on the server, the code within the <% %> tags is executed and any output placed in their position. All other characters within the ASP source are left as they are. So the line break after the initial closing %> tag is left as it is.

The only way around it is the way that you have yourself suggested. ie:

<%pippa="Camilla"%><!DOCTYPE html>

Not pretty, but it works.

Need Your Help

Unable to connect to Web Developers built in web server windows webserver visual-web-developer

When I yesterday returned to Visual Web Developer I was no longer able to run/debug my projects. Clicking the green play button launches ASP.NET Development Server (and it shows up in the systray) ...

How to find an element from an element in iOS using appuim

java ios selenium appium

As shown below, I want to check if there is a UIAStaticText for each of the UIACollectionCell.