tags:

views:

22

answers:

2

How do I display an html document in an asp control, preferably an asp:table, programmatically from server side script? I currently open the html document with a Streamrader, read it into a string, then put it into the table, but all the html markup appears. I tried using HtmlEncode, and HtmlDecode, but cannot get it to work. So I have the mechanics of accessing the control working, just need to render the html document as it would appear in a browser.

A: 

You would need to set the ".InnerHtml" property of some control (HtmlCell?) instead of ".InnerText" or perhaps something like:

LiteralControl foo = new LiteralControl("<p>html from stream here</p>")
table.Rows[0].Cells[0].Controls.Add(foo);

It would help if you would provide some context (a small code example) of what exactly are you trying to do when you put the html "into the table".

Ope
Solved: I removed the line with HtmlEncode
bill seacham
OK, the whole StringWriter-business was redundant: if you already have it as string from GetArticle(), you can put it to InnerHtml directly.
Ope
A: 

Here is my current code:

//articleComments in code snippet is the raw html file contents

protected void DisplayArticle(string articleID)
    {       
        string articleContents = GetArticle(articleID);
        System.IO.StringWriter sw=new System.IO.StringWriter();
        Server.HtmlEncode(articleContents, sw);
        Server.HtmlDecode(articleContents, sw);
        HtmlTableRow row = new HtmlTableRow();
        HtmlTableCell cell = new HtmlTableCell();
        this.tablearticle.Border = 0;
        this.tablearticle.Rows.Add(row);
        row.Attributes.Add("bgcolor", "lightgrey");
        row.Attributes.Add("align", "center");
        cell.InnerHtml = sw.ToString();
        row.Cells.Add(cell);
    }
bill seacham