简体   繁体   English

获取render事件中某个div的html代码

[英]get the html code of a certain div in the render event

There is a way to get the html value of a div in the page render event with many asp:Label's inside? 有一种方法可以在页面渲染事件中获取div的html值,其中包含许多asp:Label?

protected override void Render(HtmlTextWriter writer)
{
    // *** Write the HTML into this string builder
    StringBuilder sb = new StringBuilder();
    StringWriter sw = new StringWriter(sb);
    HtmlTextWriter hWriter = new HtmlTextWriter(sw);
    base.Render(hWriter);
    string valdiv = DivCliente.InnerHtml;
    // *** store to a string
    string PageResult = sb.ToString();
     ...........
}

Like this way, I get the whole page in PageResult (that's almost I want), but I only want the html result of a certain div (with a known id), to print that html code(with all those labels that now are rendered as text) into a pdf. 以这种方式,我在PageResult中获得整个页面(几乎是我想要的),但是我只希望某个div(具有已知ID)的html结果打印该html代码(具有现在呈现的所有这些标签)作为文本)转换为pdf。

I tried with the InnerHtml property of the div but I get an exception "You can not get the internal value of the div because it's not a Literal" 我尝试使用div的InnerHtml属性,但出现异常“您无法获得div的内部值,因为它不是文字的”

Any idea? 任何想法?

Thanks! 谢谢!

David. 大卫。

I'm a bit rusty on my WebForms coding, but can't you just do DivCliente.Render(my writer) or something similar? 我对WebForms编码有点生疏,但是您不能只做DivCliente.Render(my writer)或类似的东西吗?

http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlcontrol.render.aspx http://msdn.microsoft.com/zh-CN/library/system.web.ui.htmlcontrols.htmlcontrol.render.aspx

It may have some unintended side effects on the div control's state, I'm not sure. 我不确定,它可能会对div控件的状态产生一些意想不到的副作用。

Why do you need the DIV's contents? 为什么需要DIV的内容?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM