Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanna apply the below class background color dynamically from code behind.. Is that possible? Thanks in advance.

What I have tried:

CSS
body 
{
	width:100%;
	height:100%;
	/* background:none repeat scroll 0 0 #d3d3d3; */
	background: -webkit-linear-gradient(#b53e36, #cccccc); /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(#b53e36, #cccccc); /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(#b53e36, #cccccc); /* For Firefox 3.6 to 15 */
  background: linear-gradient(#b53e36, #cccccc) no-repeat; /* Standard syntax */
	font-size:100%;
	margin:0;
  font-family:"Arial",sans-serif;
  color:#444;
  }
Posted
Updated 30-Dec-16 3:16am
v2

1 solution

Try this:
First, add an id and runat="server" to the body tag in aspx so that it can be referenced at code-behind:
<body id="mybody" runat="server">

Next, to add a css property to this body tag on codebehind, e.g.
mybody.Attributes.CssStyle.Add("background", "linear-gradient(#b53e36, #cccccc)");
 
Share this answer
 
v2
Comments
JanardhanSharma 31-Dec-16 0:52am    
It's working fyn. Thanks a lot.
Peter Leow 31-Dec-16 3:18am    
You are welcome.

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