简体   繁体   中英

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?

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.

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"

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?

http://msdn.microsoft.com/en-us/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.

Why do you need the DIV's contents?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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