Reputation: 20468
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
Upvotes: 4
Views: 5042
Reputation: 11
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");
}
Upvotes: 1
Reputation: 31
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")
Upvotes: 2
Reputation: 7355
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?
Upvotes: 1
Reputation: 12561
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>
Upvotes: 0