如何使用GetClientScriptsInDocument从Source View智能标记设计器访问客户端脚本

Zdr*_*lev 7 .net c# asp.net windows-forms-designer visual-studio-2015

我试图获取ASP页面的脚本节点块并通过代码实现动态修改它.为了做到这一点,我有一个自定义向导(组件设计器),我从设计视图源视图(ASP页面视图)打开.我已经在asp标记中定义了块.如果我从设计视图中打开设计器(带有智能标记),GetClientScriptsInDocument将返回现有节点,我可以修改它(例如添加一个javascript函数),尽管如果我从源视图中打开设计器,那么GetClientSciptsInDocument是返回null.

我的部分代码来自"Pro ASP.NET Extensibility"一书,我用它来获取设计器主机(通常是Visual Studio),并从那里获得RootDesigner(WebFormsRootDesigner类)和客户端脚本.

代码段:

internal ScriptNodeCollection GetScriptNodes()
{
    IDesignerHost host = this.designer.Component.Site.GetService(typeof(IDesignerHost)) as IDesignerHost;
    WebFormsRootDesigner root = host.GetDesigner(host.RootComponent) as WebFormsRootDesigner;

    if (root == null) return null;
    ClientScriptItemCollection scriptItems = root.GetClientScriptsInDocument();
    ....
}
Run Code Online (Sandbox Code Playgroud)

(this)是DesignerHelper(自定义类)类型,它继承System.Windows.Forms.Design.ControlDesigner

这是某种.NET限制吗?使用自定义设计器时,只能使用设计视图访问脚本节点块,或者我遗漏了什么?