Sha Le
Sha Le

Reputation: 93

Manipulating HTML from the asp.net code-behind

I am able to get the HTML from the code-behind, like this one:

protected override void OnPreRenderComplete(EventArgs e)
{
    StringWriter sw = new StringWriter();
    base.Render(new HtmlTextWriter(sw));
    sbHtml = sw.GetStringBuilder();
    Response.Write(sbHtml + "<!-- processed by code-behind -->");
}

But I need to remove the HTML from the Page, any help?

Upvotes: 2

Views: 1820

Answers (3)

Aristos
Aristos

Reputation: 66641

If I understand well you wish to manipulate the sbHtml, and write it out.

sbHtml = sw.GetStringBuilder();

sbHtml.Replace('anything','to anything');

Response.Write(sbHtml);

(or is something else ?)

Upvotes: 3

Chuck Savage
Chuck Savage

Reputation: 11955

Did you want a method like this to strip the HTML?

public static string StripHTML(string HTMLText)
{
    var reg = new Regex("<[^>]+>", RegexOptions.IgnoreCase);
    return reg.Replace(HTMLText, "").Replace("&nbsp;", "");
}

Upvotes: 2

Cortright
Cortright

Reputation: 1174

You can put an <asp:placeholder> on the page and set the contents to whatever you want. Add/remove/whatever.

Upvotes: 0

Related Questions