Win Surprise Gifts!!!
Top 5 Contributors of the Month
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
CrystalReportViewer control is not loading when deployed to IIS in Win 2008 R2 machine
Crystal report not loading from remote-shared folder
Error creating a Service Reference for wsdl file
Exception handling using NLog tool
How to open local system folder from the browser
A potentially dangerous Request.Form value was detected from the client
Question about a code I need to alter
validate the major code from the database in asp.net using c#
Microsoft VBScript runtime error ''800a01ad'' ActiveX component can''t create object
Scenario Name is longer than the width of the column, it''s breaking the name of the scenario in the
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