tags:

views:

66

answers:

3

I have a section in an ASP.NET page that has some <% and %> that I do NOT want the ASP.NET compiler to process. How can I specify a section to not be parsed?

+4  A: 

You can comment those sections like so:

<%-- (anything to be ignored) --%>

Or if you mean you literally have the <% and %> characters in your page, you should always use &lt; and &gt; instead of < and >.

Rex M
can't do that because they are inside a script. Apparently we are passing <% as a parameter to a flash app or some such.
Yar
Sorry, I just figured out that somebody left some Ruby code in the ASP.NET site I'm working with. I'm deleting this question now, thanks for your help.
Yar
Um, but it won't let me delete :)... thanks again. I still would like to know how to tell ASP.NET to ignore a part of the page.
Yar
A: 

Not quite sure what you mean, but you can escape the < and > using their HTML entity equivalents - &lt; and &gt;.

Dan Diplo
+1  A: 

There's not a general built-in way to accomplish this. However, if there is no complex logic in the code blocks, you can try the following:

  • overload rendering of the page (for example load it in a master page)
  • open the .ASPX file and manually read in the text and put it in a StringBuilder
  • identify and HTMLEncode the code blocks before inserting into the StringBuilder
  • feed the resulting text into Server.Execute() as if dynamically rendering a page or custom control.
Jeff Leonard
Excellent, thanks for this. The question has turned out to be moot because I was trying to avoid parsing RoR code that was copied and left intact by mistake. I see how the HTMLEncode might work, but the problem is that it (would have been) was script code so it couldn't be rendered as < etc.
Yar