views:

701

answers:

4

Does anyone know of a way that I can stop all the .NET AJAX scripts from rendering, even if a ScriptManager exists on the page?

The ScriptManager's Visible property has been overridden and disabled so that you receive a NotImplementedException if you try to set the Visible property.

The reason I would like to do this is that I don't want these large chunks of javascript all over my pages when they are not required. The ScriptManager needs to be included on the master page to ensure that only one ScriptManager is added, but it would be stupid to to have to have two versions of the same master page - one ajax enabled and one not.

Edit: I am actually using Telerik's RadScriptManager with RadAjax, in case anyone knows a method using these classes instead.

A: 

Instead of using it as an actual control in the master page, create an instance of it and add it to the page if needed; perhaps even have a property on your master page that controls whether or not it gets included.

Nicholas H
A: 

An option you could check out might be to use ScriptManager's CompositeScript block. That way, you can merge them all into 1 browser-cachable script-resource call. You can also add any other common scripts into this block too.

There is a screencast about it, I've used it before and it seems to work pretty well.

Brendan Kowitz
+2  A: 

Check out Bertrand LeRoy's "Using ScriptManager with other frameworks"

http://weblogs.asp.net/bleroy/archive/2008/07/07/using-scriptmanager-with-other-frameworks.aspx

Contains a control that inherits from ScriptManager which undoes some of its built-in script additions and allows you to replace it with whatever framework you like.

David
A: 

I have solved a similar problem - namely: programmatically in- or excluding a HoverMenuExtender from the Ajax Control Toolkit - by wrapping it inside a <asp:PlaceHolder> tag which allows setting its Visible property in code-behind. If the placeholder is invisible, it will not be rendered onto the page - including all child controls. Haven't tried it with the ScriptManager but it could work here as well.

Cheers, Oliver

Oliver