20

What's the equivalent of <%-- --%> in ASP Classic?

I have to modify a legacy ASP application and I'd like to comment out a block of HTML:

<td>
    some table cell I'd like to comment out, including
    some <%= inlineServerSideVBScriptExpressions() %>
</td>

Wrapping everything in <%-- ... --%>, as I'd do in ASP.NET, doesn't work and results in the compilation error "Expected statement". HTML comments <!-- ... --> are not an option either, since the inline ASP expressions would get evaluated and fail.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Heinzi
  • 167,459
  • 57
  • 363
  • 519

10 Answers10

29

Try this:-

<!-- METADATA  
  Your comments here
-->

The METADATA indicates to the ASP processor that this is a comment that does not need to be sent to the client.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Now that sounds promising -- I'll give that a try tomorrow. Is that stuff documented somewhere? I tried googling for `asp "METADATA directive"` and found a lot of references but no "official specification"... – Heinzi Dec 14 '10 at 13:23
  • 4
    Work like a charm! Still, are you sure this is always interpreted as a comment (i.e. ignored)? The examples I found online using METADATA always *do something* (load some COM component, etc.) based on the stuff following METADATA. I've found this: http://msdn.microsoft.com/en-us/library/ms525307.aspx, which seems to imply that the main purpose of METADATA is to load libraries. So, I'm wondering if the possibility to use it for "commenting out" stuff is just an (accidental?) side-effect... – Heinzi Dec 15 '10 at 14:20
  • @Heinzi I would agree it's not designed to be a server side comment block but as a hack it works well. +1 – user692942 Aug 06 '14 at 15:55
  • 1
    I'm not sure I agree with the statement - *"The `METADATA` indicates to the ASP processor that this is a comment that does not need to be sent to the client."* I think you have used a bit of poetic licence there, in my view it is more a happy side effect of the [TypeLibrary Declaration](http://msdn.microsoft.com/en-us/library/ms525307(v=vs.90).aspx) mechanism. – user692942 Aug 06 '14 at 16:07
  • 2
    This seems like a very dangerous way to comment proprietary server-side code. The enclosing markup would imply that sans whatever processes the `METADATA` directive, this is a plain HTML comment. – le3th4x0rbot Aug 09 '14 at 21:34
  • Regardless of the implication, @trognanders, this works perfectly with minimal cruft and allows for comment blocks of arbitrary size. Classic ASP is now a legacy language so its syntax and implementation are unlikely to change. Whoever discovered this 'cheat' is a damned genius. In my opinion, this absolutely deserves to be the accepted answer. – Frank Bailey Dec 07 '18 at 13:06
  • 1
    @FrankBailey This is definitely not part of ASP Classic, but seems to live somewhere further up in the IIS stack. No warranty that it will always work since the thing that parses it may very well change. No warranty that it will work across all versions of IIS equally. How hard does TypeLibrary work to determine that the contents are all invalid? What if some of the contents *are valid*? Insidiously if the METADATA thing does nothing it is just an HTML comment that could easily be missed in testing, but still remain in the server response for the even lightly curious. – le3th4x0rbot Dec 08 '18 at 06:59
  • @trognanders I understand where you're coming from, however the stacks where classic ASP is currently deployed aren't necessarily going to be upgraded continuously, so there's no doubt a percentage of devs tasked with maintaining legacy classic ASP apps will be able to make use of this hack (and it most certainly _is_ a hack) for the foreseeable future. – Frank Bailey Dec 08 '18 at 08:38
20

There's no "built-in" way to do block comments in ASP Classic. You have to put a ' before each line you don't want to run.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
esvendsen
  • 1,492
  • 1
  • 12
  • 16
  • 1
    ...*and* put a space between all occurrences of `%>` within that commented block. That's what I'm currently doing; too bad there isn't a more elegant solution. – Heinzi Dec 13 '10 at 17:09
  • Accepted, since your first sentence answers my question. (Not the answer I was hoping for, but still...) – Heinzi Dec 13 '10 at 17:10
  • 3
    Actually its only VBScript which doesn't have a block comment mechanism, its easy to confuse ASP with VBScript because quite often people say "ASP" when they mean "VBScript inside an ASP page". Javascript has /* */, HTML has . The ASP script processor also has one, see my answer below. – AnthonyWJones Dec 14 '10 at 12:31
8

Here is how I can easily comment out an entire block of mixed code:

<% If False Then %>
  <html stuff></html stuff>
  <% more asp stuff %>
<% End If %>

If I had to do this many times I would make some kind of macro for my computer to do this via hotkey.

Vasily Hall
  • 891
  • 10
  • 22
  • 2
    That's a clever little solution to an annoying problem. Beyond the problem of having to ever work in classic asp again... – Michael A Jul 20 '17 at 23:57
6

Apostrophe-style comments are supported in VBScript. They might work here.

These are removed when the script is processed, and aren't sent to the browser.

<%
   'This line and the following two are comments.
   'The function below does something ineluctable.
   'So don't mess with it.
   SomeFunction()
%>

Here is a source for this.

Heinzi
  • 167,459
  • 57
  • 363
  • 519
DOK
  • 32,337
  • 7
  • 60
  • 92
  • 1
    +1. Yes, that's the workaround I'm currently using. I was hoping there'd be some block-level construct like <%-- ... – Heinzi Dec 13 '10 at 17:10
  • 1
    @Heinzi It is very possible that a text editor can help you add/remove comments like this in bulk. – le3th4x0rbot Aug 09 '14 at 21:35
4

This is what source control is for. Just delete the code and mark it appropriately when you check it in so you can find the snippet later if you need it.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • +1. In general, I agree, and we do use version control for our (current .net-based) projects. For various reasons, this is not an option for this legacy project. – Heinzi Dec 13 '10 at 17:13
  • 1
    Yep, nobody is switching their ASP classic project to version control. – le3th4x0rbot Apr 23 '13 at 22:53
  • 2
    @BaileyS Run all my classic asp projects through SVN repositories and would never go back. – user692942 Aug 06 '14 at 16:00
  • 2
    @Lankymart, I put the whole pile of mine in Mercurial about three months ago. You are 100% right, and I am eating my humble pie. – le3th4x0rbot Aug 09 '14 at 21:29
3

@Heinzi: Since you can't use Joel Coehoorn's excellent solution, you could also use something like

<%
Dim blnDebug : blnDebug = True

If NOT blnDebug Then
    ' Display mixed HTML/ASP code
%>
HTML, HTML .. <%=someASPfunction() %> .. more HTML
<%
End If
%>

...and then hack away at the file and when you're ready to turn on the code you've effectively "commented out", just set blnDebug to False. It beats putting apostrophes in front of every in-line code call for me.

stealthyninja
  • 10,343
  • 11
  • 51
  • 59
2

I know that you can do that in Dreamweaver; I saw my colleague doing it. But I am using Visual Studio or Notepad++ most of time, and this feature is not working there.

So I am commenting multiple lines using special pasting of a single quote, ', by pressing:

Shift + Alt + arrow down or up, then adding a single quote, '.

And the same for uncommenting the ' by selecting all 's in all lines and then delete.

Enter image description here

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301
0

The way I always comment out is using:

<%'=Var%>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Robbie Done
  • 1,157
  • 9
  • 22
0

I'm using a similar solution to @Vasily Hall answer

I'm using Sublime so I need to visualise the comment to my IDE too

<% if 1 = 2 then 'comment %>
  <!--div>
   ...
   multicomment goes here
   ...
  </div -->
<% end if 'end comment %>
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Stavros
  • 743
  • 8
  • 19
0

As a personal use for local tests where you are not afraid of leaking codes, you can close the asp tag using %><!-- and continue executing codes using --><%

<%
first block to execute
%><!-- 

second block to comment out

--><%
Third block to execute
%>
Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82