Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Is it possible to edit or modify .css file at run time and save in the .css file?

I mean, i have style sheet(Default.css) with a class name changeLabelcolor. I want to make change in .css class at run time.
C#
.changeLabelcolor
{
background-color: Grey;
}

if i change the background-color from "Grey" to "Blue" in my code behind then it will make change changeLabelcolor class permanently.

What I do for this?
Posted
Updated 23-Sep-13 20:48pm
v2

 
Share this answer
 
v2
In aspx page when you have something like this with ID and runat="server" tags then you change set the attribute for href directly in server side.

ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"     Inherits="_Default" Title="title" %>
<link href="~/Styles/Default.css" rel="stylesheet" type="text/css" id="stylesheet" runat="server" />


In server side you call add the code
C#
protected void Page_Load(object sender, EventArgs e)
{
    //updates the stylesheet's href
    stylesheet.Attributes["href"] = "Newstyle.css";
    //stylesheet.Attributes["href"] = s;
}


If you are wanting to edit the css file at run time refer this link
http://stackoverflow.com/questions/1637934/is-it-possible-to-edit-or-modify-css-file-at-run-time[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900