views:

95

answers:

1

Is there a way to only add a script manager to your Web User Control if there is not one already on the page (on the main page or if you are using the Web User Control multiple times)?

Same question about adding javascript files to the page, many times I have controls that add the javascript into the head of the page for the control.

+1  A: 

Regarding ScriptManager:

I would use master pages, and include the script manager on your master page. Alternatively, if you have something like Header.ascx which you know is included on every page, you could put it there also.

Regarding javascript files:

Use the ClientScriptManager.RegisterStartupScript method to include javascript on your page. It will not produce duplicates if they share the same key name parameter.

http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx

Kyle B.
I didn't realize that about the keys, thanks a ton for that info.. Is there any disadvantage to including the script manager on every page? I don't need it on most pages.
Greg
You could minimize file size where it is not needed, but it is negligible in my opinion.
Kyle B.