views:

141

answers:

3

i'm using some components. When page render, components generate html comment tags. if i'm using this component 10 times on one page, html comments inserted 10 times.

How to remove html comment tag before render page?

+1  A: 

Use server side comments:

<%--
    Commented out HTML/CODE/Markup.  Anything with
    this block will not be parsed/handled by ASP.NET.

    <asp:Calendar runat="server"></asp:Calendar> 

   <%# Eval(“SomeProperty”) %>     
--%>

or only render the comment in Debug mode

#if DEBUG
// Add my comment for debug only
#endif
jjacka
I don't have this component source code. Only have assembly. If i have source, I'm already fix it
ebattulga
if you could fix this issue if you had source code, try this: http://www.red-gate.com/products/reflector/
TJMonk15
+1  A: 

Hey,

What kind of component? Let's say its a custom server control that renders the HTML comments. Each server control controls its process for rendering content to the browser. So HTML comments would be rendered by this control and render it directly to the browser. As an example, it would be the following: http://msdn.microsoft.com/en-us/library/aa338806%28VS.71%29.aspx You could create your own class that inherits from this component and change the rendering process, but that is inefficient.

You could use javascript to potentially do this, but I have to ask why are these comments an issue? THey may not be rendered to the browser when your application is built in release mode...

HTH.

Brian
Because this comment contains too many code and text.
ebattulga
OK. Unfortunately, it leaves you out of the rendering process; I wish there was an easy way, but I do not know of any way to simply override some of the internal processes, unless they allow you to configure it (turn it off via a property), or use JS code to remove comments, which I think you can do but is not 100% sure... If you have support, you could make a request to add a property as a feature, to turn this off.
Brian
+1  A: 

Create a custom server control based on the 3rd party assembly, like so:

namespace ServerControls
{
    [ToolboxData("<{0}:LabelWithComment runat=server></{0}:LabelWithComment>")]
    public class LabelWithComment : Label
    {
        protected override void Render(HtmlTextWriter output)
        {
            var htmlFromBaseClass = new StringBuilder();
            var htmlTextWriterForBaseClass = 
                new HtmlTextWriter(new StringWriter(htmlFromBaseClass));
            base.Render(htmlTextWriterForBaseClass);
            var modifiedHtml = ModifyHtmlUsing(htmlFromBaseClass);
            output.Write(modifiedHtml);
        }

        private static string ModifyHtmlUsing(StringBuilder stringBuilder)
        {
            stringBuilder.Replace("<!-- some comment -->", "");
            return stringBuilder.ToString();
        }
    }
}

Then customize the ModifyHtmlUsing method to repalce whatever you want.

Then include this directive on the page where you are using the control:

<%@ Register Assembly="ServerControls" Namespace="ServerControls" TagPrefix="Custom"  %>
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <Custom:LabelWithComment ID="lblLabelWithComments" 
        Text="Some Text <!-- some comment -->" runat="server" />
    </div>
    </form>
</body>
</html>
Fernando Cardenas