0
<div runat="server" class="labels" style="display:none; height: 100%; font-family: 'Segoe UI';">
     <asp:Label ID="Label4" runat="server" Text="Description:" Font-Bold="True"></asp:Label>&nbsp;
     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
     <br />
     <asp:Label ID="Label5" runat="server" Text="Impact:" Font-Bold="True"></asp:Label>&nbsp;
     <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
     <br />
     <asp:Label ID="Label6" runat="server" Text="Recommendation:" Font-Bold="True"></asp:Label>&nbsp;
     <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
     <br /><br />
</div>

I want to change style to display:true as it is know on display: none and i want to done it using c# code. how to call class name and change its style/attributes...

2 Answers 2

2

First give an id to your div like this

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

And then in your C# code write this to add style to div.

string style = div1.Style[HtmlTextWriterStyle.Display];

if(style.ToLower()=="none")
   div1.Style.Add(HtmlTextWriterStyle.Display, "block");

And here is how you can remove style.

div1.Style.Remove(HtmlTextWriterStyle.Display);
Sign up to request clarification or add additional context in comments.

2 Comments

But also need to add check if div1 has display : none. If yes then add this code div1.Style.Add(HtmlTextWriterStyle.Display, "block");
i want to remove display:none from style
0
<% var display = "block"; 
   if(isHidden){
       display = "none";
   }
%>

<div runat="server" class="labels" style="display:<%=display%>; height: 100%; font-family: 'Segoe UI';">
     <asp:Label ID="Label4" runat="server" Text="Description:" Font-Bold="True"></asp:Label>&nbsp;
     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
     <br />
     <asp:Label ID="Label5" runat="server" Text="Impact:" Font-Bold="True"></asp:Label>&nbsp;
     <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
     <br />
     <asp:Label ID="Label6" runat="server" Text="Recommendation:" Font-Bold="True"></asp:Label>&nbsp;
     <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
     <br /><br />
</div>

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.