1

my stylesheet is ;

.rsAptContent{ background-color: transparent !important; margin: 5px !important;}

is it possible creating like this in code behind ?

6
  • for specific controls or just generally for the page? Commented Jan 29, 2013 at 14:54
  • See this Question stackoverflow.com/q/4147370/108847 Commented Jan 29, 2013 at 14:55
  • So you want to create a CSS class in code-behind (what the purpose then)? Or just want to add existing class to an element? Commented Jan 29, 2013 at 14:55
  • Response.Write could do that I think.. Commented Jan 29, 2013 at 14:56
  • i want to create css class in code behind not existing class. For example .rscontent{bla bla..} i want to create this for general page. Commented Jan 29, 2013 at 15:01

2 Answers 2

0

css file is text file with extension .css and using StreamWriter class in C# it can be generated like any other text file

Sign up to request clarification or add additional context in comments.

Comments

0

Its a little hard to understand your question as it is not well formed, but im giving it a go, here is several possible solutions that might fit your question.

If you want to read out the css file to a textbox do this

//To read/load the file
Output = File.ReadAllText(Server.MapPath(Request.ApplicationPath) + "StylesheetPath.css");
//To write/save the file
File.WriteAllText(Server.MapPath(Request.ApplicationPath) + "StylesheetPath.css", Input);

If you want to write the css on you page dynamically on each pageload you can do this.

string styles = ".rsAptContent{ background-color: transparent !important; margin: 5px !important;}"
HeaderID.InnerText = "<style>"+styles+"</style>";

I would not recommend doing this, at it will steal the CPU at each load, its better to change between several static stylesheet's like this

string stylesheet = @"\style1.css";
Head1.InnerText = "<link href=\"" + stylesheet + "\" rel=\"stylesheet\" type=\"text/css\" />";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.