[英]Manipulating HTML from the asp.net code-behind
I am able to get the HTML from the code-behind, like this one:我可以从代码隐藏中获取 HTML,如下所示:
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?但我需要从页面中删除 HTML,有什么帮助吗?
If I understand well you wish to manipulate the sbHtml, and write it out.如果我理解得很好,您希望操纵 sbHtml,并将其写出来。
sbHtml = sw.GetStringBuilder();
sbHtml.Replace('anything','to anything');
Response.Write(sbHtml);
(or is something else?) (或者是别的什么?)
Did you want a method like this to strip the HTML?你想要这样的方法来剥离 HTML 吗?
public static string StripHTML(string HTMLText)
{
var reg = new Regex("<[^>]+>", RegexOptions.IgnoreCase);
return reg.Replace(HTMLText, "").Replace(" ", "");
}
You can put an <asp:placeholder>
on the page and set the contents to whatever you want.您可以在页面上放置一个<asp:placeholder>
并将内容设置为您想要的任何内容。 Add/remove/whatever.添加/删除/随便什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.