Question

How can I embed comments in .aspx file so it is compiled out -- ie. not visible on "view source"

Asked by: roricka

In the old asp days,

<% ' a comment %>

could appear anywhere in the <body> of an .aspx file and it would  be invisible to a "view source". Is there a way to do this same thing in .NET (I'm using c#).

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-03-06 at 12:13:15ID23220929
Tags

Microsoft

,

.NET

,

2003

,

embedded comments in source

Topics

Programming for ASP.NET

,

.Net Editors & IDEs

,

Microsoft Visual C#.Net

Participating Experts
2
Points
500
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ASP to ASPX
    [VB.NET] I still have a few legacy ASP pages in my ASP.NET project that I'd like to convert over to ASP.NET. I read somewhere recently where someone said (call be gullible) that you can basically convert a "classic" ASP page to ASP.NET just by changing the file ex...
  2. Embed aspx into html
    how can you Embed aspx into an html page?
  3. Aspx Scripts
    This issue is about Microsoft dot net environment. I inherited a web site with aspx files. I have taken a class in dot net but I'm novice at it. I am a 10 year expericenced web developer with LOTS of asp, php, javascript, etc. experience. We are adding a new type of order t...
  4. Convert HTML to ASPX or ASP to ASPX easily?
    I am working on a sharepoint site and I have to have users login through web page. I have html template I made that I want to use but I need to convert that to aspx format. I think I have way to convert html to asp but not to aspx and I don't know if there is any software I c...
  5. asp & aspx
    can asp and aspx pages reside in the same virtual directory?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: SteveH_UKPosted on 2008-03-06 at 12:19:01ID: 21064263

You can use a similar tag in ASP.NET

<%-- comment here --%>

See http://msdn2.microsoft.com/en-us/library/4acf8afk.aspx

 

by: daleyjemPosted on 2008-03-06 at 13:46:48ID: 21065126

comments in C# use two forward slashes.

i believe this should work:
<% // Some comment %>

 

by: rorickaPosted on 2008-03-06 at 16:25:34ID: 21066148

For some reason, <% -- comment %> doesn't work -- only the c# delimiter does.

 

by: SteveH_UKPosted on 2008-03-06 at 22:29:40ID: 21067786

roricka:  probably didn't work because of a space after the first % character.

You shouldn't use the // comment in the page layout for several reasons:

1.  It doesn't block the sequence %> which means you can't surround wider blocks of code
2.  It makes your ASPX code language-dependent, which it doesn't need to be
3.  The <% // comments don't work around tags, such as <asp:Button>
4.  The use of <% blocks makes the ASPX code unreadable.

 

by: SteveH_UKPosted on 2008-03-06 at 22:30:48ID: 21067791

Remember, the sequence is:

<%--

comments

--%>

The sequence of characters is repeated at both ends.

 

by: rorickaPosted on 2008-03-06 at 23:44:53ID: 21068102

SteveH UK

Excellent. Now, how do I reassign the points?

 

by: SteveH_UKPosted on 2008-03-07 at 00:23:15ID: 21068253

You would need to alert a moderator for this zone.  Comments can be made in the Community Support Zone.

 

by: daleyjemPosted on 2008-03-07 at 06:04:03ID: 21069992

what about blocking like this:

<% /*

comments

*/ %>

...cause that's actually the multi-line way of using the forward slash.

 

by: SteveH_UKPosted on 2008-03-07 at 06:39:30ID: 21070402

daleyjem:

multiline comments are useful in code files but they suffer with the same tag issues in an ASPX file.

 

by: daleyjemPosted on 2008-03-07 at 07:57:19ID: 21071367

well honestly, i wouldn't doubt that you're more knowledgeable in this area than i... but i guess i'm a little against the idea that my points need to be stripped from me.

 

by: SteveH_UKPosted on 2008-03-07 at 09:29:51ID: 21072421

I didn't request the points and I intentionally did not instruct the author to act in any particular way.

Regarding "your points", my suggestion which came first was a) standard, b) documented and c) correct.  The only issue was the author had typed it in wrong, not anything wrong in the suggested solution, so let's not call them "your points" if you don't mind.

 

by: daleyjemPosted on 2008-03-07 at 10:19:59ID: 21072871

i don't really want to argue about who's code was better because i don't doubt that your reasoning is correct. but at the same time, the author must've tried my code with success or else he/she would not have accepted.

i think an assist would be more fair seeing as he/she DID accept my answer and not yours.

secondly, if he/she decided to throw some server-side code into the equation... it wouldn't work with your example.

you might argue that that type of thing was never suggested, but then i could argue that putting the comment into a "block" wasn't either.

 

by: rorickaPosted on 2008-03-07 at 10:34:06ID: 21073005

Now, now.

Actually, the idea of having language-independent syntax is what I was originally looking for (though didn't specify), and when it appeared as if only the "//" delimiter worked, I scratched my head, but decided it DID satisfy my original request. Had I not been so careless in trying the "--" syntax, I would have split the points.

BTW, for some reason, I can't get to the community support zone w/o pinning my CPU cycles (and on 2 different machines!)

When that calms down, I do plan on splitting the points among all the solutions that satisfied my original question. (That's the way I always do it -- at the point I review the submissions, I don't just give to the first person, but to everyone who satisfied the criteria w/original suggestions.)

That said, it appears that using the "--" approach exclusively in the future is the way to go.

Thanks all.

amabog (roricka)

 

by: SteveH_UKPosted on 2008-03-07 at 10:34:20ID: 21073009

Firstly, I disagree with your comments (both technically and more generally), but I also don't want to have this discussion.  Secondly, I never made any statement in favour or against an assist.

 

by: SteveH_UKPosted on 2008-03-07 at 10:36:27ID: 21073024

For clarification:  my most recent comment was directed to daleyjem.

amabog:  glad to help.

 

by: daleyjemPosted on 2008-03-07 at 10:36:56ID: 21073031

that's your prerogative... could you tell me exactly though what it is you disagree with? i'm only curious is all...

 

by: daleyjemPosted on 2008-03-07 at 10:47:31ID: 21073112

what i meant in mentioning server-side was:

<%--
    comment
    Response.Write("can't be done");
--%>

<%
    // comment
    Response.Write("can be done");
%>

it's just more efficient in my opinion than doing this:
<%--
    In the code snippet below, I'm going to Write something to the window.
--%>
<%
    Response.Write("something to the window.");
%>

still though... i learned a lesson on commenting with <%-- .. i honestly didn't know how to do that, so thanks.

roricka... thanks for the split

 

by: SteveH_UKPosted on 2008-03-07 at 10:54:10ID: 21073172

The typical use of the <%-- comment block is to wrap existing markup, for example the original page might have:

<p><%
/* The next line does ......
    and some more comment */
Response.Write("Some content");
%></p>

Obviously, the typical page would be more complex.  You can use a server-side comment to wrap the complete set:

<%--
<p><%
/* The next line does ......
    and some more comment */
Response.Write("Some content"); %></p>
--%>

Which you can't do with an embedded code comment.

The biggest limitation is that none of the ASP.NET comment conventions allow proper comment nesting, but the server-side comment is closest to it.

 

by: daleyjemPosted on 2008-03-07 at 10:58:51ID: 21073215

yeah, .NET can act a little fishy when it comes to certain things. eventhough the general markup of an aspx page seems to follow XML conventions, you couldn't do something like this without an error:

<asp:Table id="theTable" runat="server">
    <asp:TableRow blah blah>blah blah blah</asp:TableRow>
    <!--
        this is how you comment XML... it'll break your code though if it's in the middle of a .NET control
    -->
</asp:Table>

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...