Johnrad
Johnrad

Reputation: 2655

JavaScript - control.style.display = "none"; and control.style.display = "";?

When I created a label I set it's display to none in the designer.

<asp:Label ID="label1" runat="server" style="display:none;" Text="LABEL" asp:Label>

I use javascript to turn the label visible by:

var lbl = document.getElementById('label1');
lbl.style.display="";

WHen I do this the space is created where the label would be on the form but the label itself doesn't show up. I have tried

lbl.style.display="inline";
lbl.style.display="block";

just to see if the label would show up. Still nothing though. Just the extra space where the label would be is created.

Upvotes: 2

Views: 11913

Answers (2)

sjngm
sjngm

Reputation: 12861

You were saying

WHen I do this the space is created where the label would be on the form but the label itself doesn't show up. I have tried

That makes me believe that somewhere in your CSS you may have visibility set to hidden. That normally covers the space of the element, but doesn't show it. The display controls whether or not the space is preserved for the element.

Upvotes: 5

Jonathan Wood
Jonathan Wood

Reputation: 67239

Are you certain you have the control ID correct? Unless you set ClientIDMode to Static, the actual control ID will probably be something much longer than the ID you specify. Check the control's ClientID property.

Upvotes: 1

Related Questions