[ACCEPTED]-ASP.NET control with CSS visibility:hidden, not being shown on Control.Visible = true-visibility

Accepted answer
Score: 15

The Visible property affects rendering of the entire 9 element and is unrelated to the CSS visibility 8 attribute. When false, Visible when prevent 7 any HTML from being rendered at all.

To change 6 the css attribute, you will need to do it 5 manually. You can do this by either removing 4 the "error" class from the element 3 (via the CssClass property) or by setting a style="visibility: visible" attribute 2 manually via the Attributes property (since the style 1 attribute overrides a css class):

control.Attributes["style"] = "visibility: visible";
Score: 13

You are getting confused between CSS visibility 7 and the control's server side Visible property. To 6 understand it better I recommend you create 5 a sample page with a label, toggle the Visible 4 property between true and false and view 3 the generated HTML.

What you will find is 2 as follows. As true:

   <label runat="server" visible="true">Hello</label>

Will render:


When set 1 to false, it will render:


Score: 3

Have a look at this page, it should clarify 9 things: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.style.aspx

As written before:

The Visible property 8 is serverside and determines if the Server 7 will render the control or not (if it's 6 not rendered, no HTML will be created for 5 it, and it's not in the final HTML send 4 to the client).

The Style property controls 3 the style attribute of the element. The 2 element will be rendered but you can control 1 the visibility (CSS).

More Related questions