4

i want to get 'display' css value of a server side div!
the code below does not work :

    if (div.Style["display"] == "none")
    {
        div.Style.Add("display", "table-row");
    }

how can i get that value in c#?

thanks in advance

2
  • Are these inline styles or found in CSS styles? Commented Jun 28, 2012 at 17:56
  • in head element of aspx form i added display css of that div -> none Commented Jun 28, 2012 at 17:57

4 Answers 4

2

div.Attributes["style"].Add("display", "table-row")

Use this:

if (div.Attributes["style"].ToString().Contains("display:none;")) 
{ div.Attributes.Add("style", "display:table-row"); }

or try

div.Attributes["CLASS"].ToString().Contains("CLASS_NAME")
Sign up to request clarification or add additional context in comments.

Comments

1

You can't do that but I guess you are applying some logic to do something if your div is visible or not(dispay:none or not). If that's the case why not use an html input element and toggle its value as per need?

Comments

1

better solution:

HTML

<div id="divID" runat="server" style="display:none;"></div>

C#

if(divID.Style.Value.ToLower() == "display:none;")
{
   divID.Style.Add("display", "table-row");
}

Comments

0

You can't do what you are trying to do on the server side. The Style property only works with the inline styling. Consider client side JavaScript.

<div id="div" runat="server" style="display: none;">Foo</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.