1

I want to capture the HTML output of an asp.net page in the master page's LoadComplete event. This is what I have:

public partial class MasterPage_MyBlogMainMaster : System.Web.UI.MasterPage
{
    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        var PageURL = HttpContext.Current.Request.Url.AbsolutePath;

        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);

        HtmlTextWriter hWriter = new HtmlTextWriter(sw);
        base.Render(hWriter);

        string PageResult = sb.ToString();
    }
}

The problem is that the event doesn't seem to trigger. What do I need to change?

Thanks.

2 Answers 2

1

Ok, I got it to work; if anyone comes to this page, this is how you do it. The problem is that LoadComplete event needs to be wired in the Page_Load method, like this:

protected void Page_Load(object sender, EventArgs e)
{
     Page.LoadComplete += new EventHandler(Page_LoadComplete);
}

protected void Page_LoadComplete(object sender, EventArgs e)
{
  ... now this works
}
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe try to use HttpHandler (you can filter out not interesting pages in it also): Capturing HTML generated from ASP.NET

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.