I've created a Visual Studio SharePoint 2010 solution with an ASCX that adds some JavaScript files and CSS to the head of each page; this is based on this article. When I deploy the solution, it adds the files to the correct server folder:

But then the files aren't added to the page headers. I've gone in and activated the user control from the site features but this hasn't fixed it. Here's the simple code in the CustomPageHead.ascx.cs file; I removed the JS files to see if that was causing the issue:

Could it be that I'm trying to activate the feature from a site such as http://mydomain.org/mysite/ and the path in the code above is looking at the current site's root? But why isn't it at least adding the control to the page, even if it has the wrong path?

Thanks, omlin. The problem also was I had missed one of the steps in creating the solution as described in the article. Also, what does the base.CreateChildControls() do in the two method overrides above?
–
Alex CSep 1 '11 at 8:51

2

Base method call it is not obligatory in this particular case, you can safely clear if off. Visual Studio generates it by default :)
–
Andrey MarkeevSep 1 '11 at 9:13

+1 for CssRegistration. It has an "After" property, where you specify the name of the CSS file after which you want yours to load. This lets you cascade the styles correctly and predictably. This property is new SP2010.
–
James LoveSep 1 '11 at 12:40

What I would do is do the work in CreateChildControls. Have it just add the two LiteralControls to the this.Controls collection.

Then, add your ASCX to the AdditionalPageHead delegate control via your Feature. (step 33 in that article you linked to).

There is a reason (and at this time in the morning I can't remember what it is), but the Page.Header control never did add my controls for me. Add them to this.Controls and do it in CreateChildControls and it'll probably work fine.

This is the method I use to add CSS and jQuery libraries to all my branding projects.

Thanks, James. What's the diff between this.Controls and Page.Header.Controls? Is it a shortcut? I'm learning more and more by posting here and thanks to all the folks who reply, like yourself :)
–
Alex CSep 1 '11 at 12:13