Getting a scriptmanager into a dynamically rendered page

Posted by AndreasKnudsen on Stack Overflow See other posts from Stack Overflow or by AndreasKnudsen
Published on 2010-04-13T15:28:44Z Indexed on 2010/05/01 4:17 UTC
Read the original article Hit count: 349

Hi,

We are rendering usercontrols dynamically like this:

public string RenderControl(string pathcontrol)
{
    string html;

    var page = new Page();
    var control = page.LoadControl(path);            
    page.Controls.Add(control);

    // do stuff to the control (give it some data to work on)

    using (var writer = new StringWriter())
    {
        HttpContext.Current.Server.Execute(page, writer, false);
        html = writer.ToString();
    }

    return html;
}

This lets us the same user controls when rendering pages normally as we do when rendering responses to ajax calls. However, when adding controls which themselves contain a scriptmanagerProxy we run into the problem that the newed up Page object doesn't contain either a ScriptManager or the HtmlForm in which the ScriptManager needs to run.

Is there any way around this?

Yours Andreas

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about usercontrols