Hiding a control in Asp.net using css

I am trying to make the control invisible using css, but still the control is shown.

I tried to do it

html1.Visible = false;

but this creates a space in the menu in which it was used

HtmlAnchor html1 = (HtmlAnchor)holder.FindControl("lblA1");
html1.Attributes.Add("class", "display:none");

I want to hide the control and do not want to display a space there how we can achieve this. any help would be great

+5
source share
3 answers

You just need to use styleinstead class:

html1.Attributes.Add("style", "display:none");

You can also consider creating a CSS style, for example:

.hidden
{
   display:none;
}

And then apply it through the "class":

html1.Attributes.Add("class", "hidden");
+9
source

style, style Attributes, , ....

HtmlAnchor html1 = (HtmlAnchor)Page.FindControl("lblA1");
html1.Style.Add("display", "none");
0

You can attach this class to a button using the above methods. It is very useful when the button occupies a space that should not be

<style>
 .hideAspButton
  {
   position: absolute;
   visibility: hidden;
  }
</style>
0
source

All Articles