Win Surprise Gifts!!!
Top 5 Contributors of the Month
Kemal AL GAZZAH
Post New Question
Subscribe to Forum
How to load .css file dynamically in asp.net
October 25, 2009
How to load .css (stylesheet) file dynamically in asp.net through code in C#? i need to change for some asp.net web pages.
Posted Date: October 25, 2009 Points: 5
Sometimes its necessary to programmatically add some CSS stylesheets to your ASP.NET page, for example if you want to allow your users to change look and feel of your website by choosing themes etc.
Here is how to do it, just add this code to the Page_Init event handler on the Page where you want to insert CSS file:
protected void Page_Init(object sender, EventArgs e)
HtmlLink css = new HtmlLink();
css.Href = "css/fancyforms.css";
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
And thats it, next time you load this page, reference to your CSS file will be added at runtime to the page HTML code and loaded.
Posted Date: February 10, 2010 Points: 5
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.
Add following HTML tag in the ASP.NET (.aspx) page in the header section.
<link id="CSSFile" type="text/css" rel="Stylesheet" runat="server" />
In the code behind page you can then add the CSS file as follows by accessing the link ID
(Dynamic.css is the CSS file that has been added to the page.)
To post reply
Related Questions Related Questions
How to modify web.config file dynamically?
How to modify App.config file dynamically?
Could not load file or assembly 'ChilkatDotNet4.dll' or one of its dependencies
How to write to a text file in C#
How to copy a file from server to local system
Any alternative to using web.config file
upload image file in windows application
How to create .exe file
Add TextBox dynamically
SWF file problem
Latest Forum Questions From The Same Category
What class does Icon derive from?
What are the validation controls?
What''s the difference between an interface and abstract class?
How to read Unicode form PDF File and Save into DataBase ?
How to identify the color format of eps/tiff using c#?
Override method definition
how to get hosting URL path in global.asax
How to develop price comparison website in asp.net?
Issues in production servers
Unable to start program, there are no files
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more
Quick Links For Forum Categories:
Hall of Fame
Terms of Service
Tell A Friend