How to access client side scripts from Source View smart tag designer by using GetClientScriptsInDocument
Asked Answered
H

0

7

I am trying to get the Script node block of ASP page and modify it dynamically, through code implementation. In order to do that I have a custom wizard (Component Designer) which I am opening from Design View or Source View (ASP page view). I have already defined block in the asp markup. If I open the designer (with the smart tag) from the Design View, GetClientScriptsInDocument is returning the existing node and I can modify it (Add a javascript function for example), although If I open the designer from the Source View, then GetClientSciptsInDocument is returning null.

Part of my code is from "Pro ASP.NET Extensibility" book, I am using it to get the designer host (Usually Visual Studio), and from there the RootDesigner (WebFormsRootDesigner class) and client scripts.

Code snippet:

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();
    ....
}

(this) is of type DesignerHelper (custom class) which inherits System.Windows.Forms.Design.ControlDesigner

Is this some kind of a .NET limitation and the script node block is accessible only with the Design View when custom designer is used, or I am missing something?

Harlequinade answered 16/1, 2017 at 14:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.