HTMLTextWriter 在页面中间渲染元素

发布于 2024-12-17 13:35:33 字数 606 浏览 4 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云归处 2024-12-24 13:35:33

我认为您需要使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文