Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
how to set div opacity in asp.net using code behind c#
thanks
Posted

ASP.NET
<div runat="server" id="divi">
</div>

and in code behind:
C#
divi.Attributes.CssStyle.Add("opacity","0.5");
 
Share this answer
 
Comments
vivek.bagdai 3-Jun-12 14:07pm    
Agree with Answer,

And if there is more then one tag then you can create method
for developer Ease.
VICK 7-Jan-14 7:14am    
sorted out my problem partially.. divs getting opacity.. but i want the opacity like that none of the div's content should be accessible.. for example by applying this solution opacing comes but i m still able to click the button inside the div... :(

I know the old post.. but perhaps i could get the solution and could be helpful for others in future as well.... so posting.. :)
taha bahraminezhad Jooneghani 12-Nov-14 2:33am    
VICK you have to give the children of the DIVs different opacity , you can't apply something on the root or parents and expect it's not going to affect the children!
children.Attributes.CssStyle.Add("Opacity","1");
In ASP.Net using asp:Panel renders a div. So define a css class in a style file or in the page and from code-behind set the CssClass property (or set in the .aspx page itself.

For example, in the aspx:

C#
<asp:panel id="panel" runat="server" xmlns:asp="#unknown">

</asp:panel>


Then in the code-behind:

C#
protected void Page_Load(object sender, EventArgs e)
{
    panel.CssClass = "some-class";
}

or

C#
<asp:panel id="panel" runat="server" cssclass="some-class" xmlns:asp="#unknown">

</asp:panel>


(or)

C#
<div id="div1" runat="server">
</div>


C#
protected void Page_Load(object sender, EventArgs e)
{
   div1.Attributes.Add("class","some-class");
}


As a side note, you could also use the "style" client-side property.

Hope this helps!
 
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