ASP.NET HTML Parsing in Controls

Is it possible in ASP.NET to take a string containing some HTML and make ASP.NET to parse it and create a control for me? For instance:

string rawHTML = "<table><td><td>Cell</td></tr></table>";
HTMLTable table = MagicClass.ParseTable(rawHTML);

I know that this is bad, but I am in an unsuccessful situation, that this is the only way to achieve what I need (since I can not change this code of my colleague).

In addition, I know that LiteralControl allows you to have a control with arbitrary HTML code, but, unfortunately, I need them to be converted to the correct control.

Unfortunately, HTMLTable does not support the InnerHTML property. I need to save the HTML tree exactly as it is, so I cannot put it in a tag <div>.

Thank.

+3
source share
2 answers

, Page.ParseControl, ASP.NET. , , , LiteralControl, runat = "server" , .

:

this.ParseControl("<table><tr><td>Cell</td></tr></table>")

:

Control
 LiteralControl

:

this.ParseControl("<table runat=\"server\"><tr><td>Cell</td></tr></table>")

:

Control
 HtmlTable
  HtmlTableRow
   HtmlTableCell
    LiteralControl
+7

HTML (, HTML- HTML InnerText), , , . ... .

, "" , Literal?

0

Source: https://habr.com/ru/post/1698896/


All Articles