user2972061
user2972061

Reputation: 355

How to render CSS from code behind

Suppose I have a string which has CSS classes, I have to render it on page load.

My string value is:

.Class1 { display: none; } .Class2 { display: none; }

Upvotes: 0

Views: 262

Answers (1)

Uwe Keim
Uwe Keim

Reputation: 40736

In your ASPX page, define a Literal control like e.g.:

<asp:Literal runat="server" ID="MyCss" />

Then, in the Load event handler of your code-behind, set the text like e.g.:

protected void Page_Load( object sender, EventArgs e )
{
    MyCss.Text = ".Class1 { display: none; } .Class2 { display: none; }";
}

Depending on your usage scenario, you would nest your Literal control instance inside other HTML or server controls.

Upvotes: 1

Related Questions