Click here to Skip to main content
Click here to Skip to main content

Register a style include from code

, 12 May 2010
Rate this:
Please Sign up or sign in to vote.
public static class PageExtensions { private const string styleInclude = "$styleInclude"; /// /// Registers a client style include. /// /// The page. /// The...
public static class PageExtensions
    {
        private const string styleInclude = "$styleInclude";
        /// <summary>
        /// Registers a client style include.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="type">The type.</param>
        /// <param name="key">The key.</param>
        /// <param name="url">The URL.</param>
        /// <remarks>
        /// The link include will be registered in the header. 
        /// The header must be marked as runat="Server"
        /// </remarks>
        public static void RegisterClientStyleInclude(this Page page, Type type, string key, string url)
        {
            var styleLink = new System.Web.UI.HtmlControls.HtmlLink();
            styleLink.Href = url;
            styleLink.Attributes.Add("rel", "stylesheet");
            styleLink.Attributes.Add("type", "text/css");
            page.Header.Controls.Add(styleLink);
            page.Items[styleInclude + type.ToString() + key] = true;
        }
        /// <summary>
        /// Determines whether the client style include is registered.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="page">The page.</param>
        /// <param name="key">The key.</param>
        /// <returns>
        /// 	<c>true</c> if the client style include is registered; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsClientStyleIncludeRegistered(this Page page, Type type, string key)
        {
            return page.Items.Contains(styleInclude + type.ToString() + key);
        }
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Magnus_
Web Developer
Sweden Sweden
Software developer

Comments and Discussions

 
QuestionThis is an article? Pinmemberinetfly12312-May-10 2:36 
AnswerRe: This is an article? PinmemberPartenon12-May-10 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 12 May 2010
Article Copyright 2010 by Magnus_
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid