获得一个ScriptManager到动态呈现的页面 [英] Getting a scriptmanager into a dynamically rendered page

查看:154
本文介绍了获得一个ScriptManager到动态呈现的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将动态呈现用户控件是这样的:

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;
}

这让我们相同的用户控件呈现页面时正常,因为我们做的渲染响应AJAX调用时。然而,增加其本身含有的ScriptManagerProxy控件时,我们遇到了问题,即newed了Page对象不包含任何一个ScriptManager或其中的ScriptManager需要运行的HtmlForm。

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?

此致 安德烈亚斯

推荐答案

正如其他人所说,你可以添加的 ScriptManger 的动态很轻松了[<一href="http://stackoverflow.com/questions/183950/add-scriptmanager-to-page-programmatically">http://stackoverflow.com/questions/183950/add-scriptmanager-to-page-programmatically如果你的页面的对象是完整的。

As others have said you can add a ScriptManger dynamically easily enough [ http://stackoverflow.com/questions/183950/add-scriptmanager-to-page-programmatically if your Page object is complete.

您可以尝试使用<一个href="http://msdn.microsoft.com/en-us/library/system.web.compilation.buildmanager.createinstancefromvirtualpath.aspx"相对=nofollow> BuildManager.CreateInstanceFromVirtualPath()创建的页面的对象呢?你的问题可能是如何创建的对象。还有更多的创建一个新的页面比的 newing了的Page对象。

Can you try using BuildManager.CreateInstanceFromVirtualPath() to create the Page object instead? You issue may be how you create that object. There's a bit more to creating a new page than newing up the Page object.

例如:

Page page 
       = BuildManager.CreateInstanceFromVirtualPath("~/Test.aspx", typeof(Page))

参见 http://www.west-wind.com/weblog/文章/ 120530.aspx 多一点背景。

这篇关于获得一个ScriptManager到动态呈现的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆