HTML in C# just prints it as text in HTML file and not html code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sl1ver
    New Member
    • Mar 2009
    • 196

    HTML in C# just prints it as text in HTML file and not html code

    i have this in my C#

    Code:
    sData +=    "<div id=\"div1\"> " +
                "<img src=\"http://www.system.pushplay.co.za/images/covers/big/big_<%=vcimagename %>\" width=\"80\" height=\"100\" /> " +
                "</div>" +
                "<div id=\"div2\"> " +
                "<table> " +
                "<tr>" +
                "<td> " +
                "<%=vctitlename.Replace(\"@\",\"<br/>\") %>(<%=vccertificate %>)&nbsp;<%=intyear %>  " +
                "</td> " +
                "</tr> " +
                "<tr> " +
                "<td> " +
                "Starring: <%=titleactorlist %> " +
                "</td> " +
                "</tr> " +
                "<tr> " +
                "<td> " +
                "<%=vcshortdesc%><br /> " +
                "</td> " +
                "</tr> " +
                "</table> "+
                "</div> " ;
    
                encodedHtml = Server.HtmlEncode(sData);
    The problem is it prints it as text in the html file instead of actually making it html so that i see the page properly.

    This is what i see as a "string" once the html page is loaded

    <div id="div1"> <img src="http://www.system.push play.co.za/images/covers/big/big_<%=vcimagen ame %>" width="80" height="100" /> </div><div id="div2"> <table> <tr><td> <%=vctitlename. Replace("@","<b r/>") %>(<%=vccertifi cate %>)&nbsp;<%=int year %> </td> </tr> <tr> <td> Starring: <%=titleactorli st %> </td> </tr> <tr> <td> <%=vcshortdesc% ><br /> </td> </tr> </table> </div>
    Last edited by Frinavale; Oct 4 '11, 03:11 PM.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    ASP.NET automatically does this for you because it wants to make sure that HTML isn't inserted into the page by accident. You need to turn encoding off for that control.

    Why oh why would you take this approach though??
    It would make a lot more sense to use a proper Repeater or Table or GridView or some other control...

    -Frinny

    Comment

    Working...