This project is read-only.

Custom CSS/Custom Head Section

Topics: ASP.NET 2.0, Business Logic Layer, Controls, Themes
Apr 1, 2011 at 9:05 AM

I'm trying to include a gallery on a page. I know there are extensions, but none match the functionality I need. I have a usr control which loads the gallery images, but I can't figure out ho to include a custom section in the head (either from the user control or from the blogengine Page itself).

Is there a way I can include a custom section in the head, or just a css file per page?

I'm using the following to inject the usercontrol:
[usercontrol: ~/User Controls/CMS/ContentImageGallery.ascx;GalleryName=Gallery1]

Apr 1, 2011 at 11:30 AM
Edited Oct 24, 2011 at 9:45 PM


So suppose you have created an user control let's say MyUserControl.ascx which resides in let's say usercontrols folder in the root of your website.

You want to add this user control somwhere in your blog post, then simply add the following line into the editor. look for any references of user controls in the post contents and renders the user control at the place where it was embeded if it found any along with the blog post content.

Java Blog

Apr 1, 2011 at 12:15 PM

I'm already using that syntax  to insert the usercontrol. How would that let me insert custom CSS into the head?

Apr 1, 2011 at 12:50 PM


i've written a short article about adding custom scripts to the head section of the page. Nearly the same applies to styles. Take a look at

Apr 2, 2011 at 7:29 PM
Edited Apr 2, 2011 at 7:30 PM

That looks like a good idea from rkuss for registering scripts.

If it's just the CSS you want to add, you could try something like this.

Add to your user control code

private void LoadCSS()
        HtmlLink css = new HtmlLink();
        css.Attributes["type"] = "text/css";
        css.Attributes["rel"] = "stylesheet";
        css.Attributes["href"] = "/themes/yourtheme/css/yourcss.css"; //path to your css



Then call that from one of the user controls's loading functions, you would probably want to add some kind of guard so that you don't load the same file repeatedly.

Or adapt the RegisterScriptFile to RegisterCSS if you're looking for reuse.