If you simply want to remove comments from code before they are rendered to the client, then change the way you are commenting. Use server-side comments = <%-- hi --%>
:
So this:
<!-- Don't remove the <p> below because our stupid clients are too stupid to figure out this form without it -->
<p>Tip: The field labeled "First Name" is meant for your first name. Don't type in your last name in this box.</p>
<%-- Don't remove this <p> either because both our clients and our boss are too dumb to figure it out --%>
<p>Tip 2: Type your last name in the field labeled "Last Name".</p>
Will be rendered as:
<!-- Don't remove the <p> below because our stupid clients are too stupid to figure out this form without it -->
<p>Tip: The field labeled "First Name" is meant for your first name. Don't type in your last name in this box.</p>
<p>Tip 2: Type your last name in the field labeled "Last Name".</p>
But, if you actually need to edit output HTML before rendering to the client on a global scale, and you can't just fix it in the code, you could do this in the master page:
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
base.Render(tw);
string yourHTML = sw.ToString();
// do stuff with yourHTML
writer.Write(yourHTML);
tw.Dispose();
sw.Dispose();
}
So in a very simple example, if you have the code
<h1>I'm a big fat h1</h1>
you could in that function have:
yourHTML = yourHTML.Replace("<h1>","<h5>");
yourHTML = yourHTML.Replace("</h1>", "</h5>");
So now that above code is rendered as
<h5>I'm a big fat h1</h5>
To fulfill the very legit requirement to change all h1
tags to h5
before they are rendered to browser.