tags:

views:

238

answers:

1

So, I'm trying to get the HTML of a Page using the following code:

var stringWriter = new StringWriter();
var htmlTextWriter = new HtmlTextWriter(stringWriter);
Page.RenderControl(htmlTextWriter);
htmlTextWriter.Flush();
var html = stringWriter.ToString();

This fails with the message Script control 'ace' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().

The control ace is an AlwaysVisibleControlExtender from the Ajax Toolkit.

<ajaxToolkit:AlwaysVisibleControlExtender ID="ace" runat="server"
    TargetControlID="lblControl" VerticalSide="Middle" 
    VerticalOffset="50" HorizontalSide="Center" HorizontalOffset="50"
    ScrollEffectDuration=".1" />

What's causing this error? How can I get around it? The page works fine when I navigate to it, the problem only occurs when I try to render the HTML to a string.

A: 

Seems that you are rendering the control and not the parent. If your parent aspx page has the ajax register script control on it you need to register it. Try and send a delegate back to the parent to render the page.

Andrew Halnan
Hi Andrew. I tried moving my code to the Page, but to no avail. Thanks for the answer, though!
Matt Grande