HTMLTextWriter 在页面中间渲染元素
使用 asp .net 和 C#,我成功地在重写 Render 方法中使用 HTMLTextWriter 来渲染两个 div。但它们出现在页面的末尾,如果我需要它们出现在特定的 asp 面板中,我该如何选择在哪里渲染这些 div?
非常感谢,
丹
编辑:我的代码:
protected override void Render(HtmlTextWriter writer)
{
StringWriter stringWriter = new StringWriter();
base.Render(writer);
using (HtmlTextWriter writer2 = new HtmlTextWriter(stringWriter))
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, "testDiv");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.RenderEndTag();
}
}
Using asp .net and C# I've managed to use a HTMLTextWriter in my override Render method to render two divs. But they appear at the end of the page, how can I choose where to render these divs if I needed them to appear in a particular asp panel for example?
Thanks a lot,
Dan
EDIT: My bit of code:
protected override void Render(HtmlTextWriter writer)
{
StringWriter stringWriter = new StringWriter();
base.Render(writer);
using (HtmlTextWriter writer2 = new HtmlTextWriter(stringWriter))
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, "testDiv");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.RenderEndTag();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要使用 HTML 解析器,例如 Majestic。您可以将页面渲染到内存流中,然后根据需要对其进行操作。
如果唯一的问题是自定义面板呈现,您可以编写一个继承
asp:panel
的控件并插入所需的类。I think you´ll need to use a HTML parser like Majestic. You can render your page into a memorystream and then manipulate it as you want.
If the only problem is to customize the panel rendering, you can write a control that inherits
asp:panel
and inserts the desired classes.