views:

49

answers:

1

I'm writing a custom class library that contains custom controls (not user controls). I have some embedded javascript files that need to be registered on the page.

Now since this is a class library, how do I detect whether or not to use a ToolKitScriptManager or ScriptManager?

Page.ClientScript is a ClientScriptManager, but would I do if the page has the new ToolKitScriptManager?

A: 

You can determine if the page your control is being instantiated in is using a ScriptManager by calling the static ScriptManager.GetCurrent() method. If this returns null then you could assume that (working on the basis that your controls will only be used within your websites), the page is utilising a ToolKitScriptManager rather than a ScriptManager.

Rob
Assuming that the page utilizes a ToolKitScriptManager and the method returns null, then what is the most effective way to find the ToolKitScriptManager? Loop through the pages controls until I find it?
Matt
Given that `ToolKitScriptManager` derives from `ScriptManager` I'd suspect that calling `ScriptManager.GetCurrent` would return (for a page that contains a ToolKitScriptManager) a reference to ToolKitScriptManager (for a page that contains one, cast as a ScriptManager) or a reference to a ScriptManager, so if either is on the page you shouldn't get `null` returned...
Rob