Extract Html content of a webpage

Posted by Community Admin on 04-Aug-2018 13:11

Extract Html content of a webpage

All Replies

Posted by Community Admin on 19-Jan-2012 00:00

HI.
iam facing some issues while extracting html content.
i have created a page which is inheriting a master page having 2 placeholders.
1 placeholder i have image and text and in  2 placeholder i have usercontrol which has a button. on click of button iam extracting html content of image and text from 1placeholder
this is the code iam using for extracting html

protected void btn_ExtractHtml_Click(object sender, EventArgse)

 
Control c = new Control();
ContentPlaceHolder cp = (ContentPlaceHolder)this.Page.Master.FindControl("ContentPlaceHolder1");
string strhtml = renderControl(cp);



public string renderControl(Controlcntr)


StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
cntr.RenderControl(hw);
return sb.ToString();

 

 iam geeting only Tags without content as shown below

<div class="sfimageWrp">

</div><div class="sfContentBlock">

</div>
i need content of this tags can anyone help me on this.
i have attached masterpage and webpage.

Posted by Community Admin on 24-Jan-2012 00:00

Hello Amaresh,

You can't get the rendered HTML source in the OnClick event of a Button control - it's too early in page lifecycle. What you can do is assign a code-behind class to a page as per this blog post -

http://www.sitefinity.com/blogs/petermarinov/posts/11-12-27/sitefinity_and_the_asp_net_code-behind_model.aspx 

and override the Render method of the page like this -

protected override void Render(HtmlTextWriter writer)
    var sb = new StringBuilder();
    var tw = new HtmlTextWriter(new System.IO.StringWriter(sb));
    base.Render(tw);
    string sContent = sb.ToString();
    writer.Write(sContent);

Regards,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed