Adding a CSS file dynamically in ASP.NET

8:44:00 pm 0 Comments


If your application targets different user-groups, you may feel the need to customize the layout of the page to display group-specific visual interface. This can be achieved by using customized CSS files that are added dynamically.  
You can add CSS files in to ASP.NET webpages dynamically. Let me show you how.
  1. Add following HTML tag in the ASP.NET (.aspx) page in the header section.
    <link id="CSSFile" type="text/css" rel="Stylesheet" runat="server" />
  2.  In the code behind page you can then add the CSS file as follows by accessing the link ID
    CSSFile.Attributes.Add("href", "Dynamic.css")

    (Dynamic.css is the CSS file that has been added to the page.)

0 comments: