I am trying to get the Script node block of an ASP page and dynamically modify it using a code implementation. To do this, I have a custom wizard (Component Designer) that I open from Design View or Source View (ASP page view). I already defined a block in asp markup. If I open the constructor (using the smart tag) from the Design View, GetClientScriptsInDocument returns the existing node, and I can change it (for example, add the javascript function), although if I open the constructor from the original view, GetClientSciptsInDocument returns null.
Part of my code from the book "Pro ASP.NET Extensibility", I use it to get the developer node (usually Visual Studio), and from there - 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 from System.Windows.Forms.Design.ControlDesigner
Is this some kind of .NET limitation, and the Script node block is only accessible via Design View when a custom constructor is used, or am I missing something?
source share