Extract Html content of a webpage
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.
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);