happysmile
happysmile

Reputation: 7777

Hiding a control in Asp.net using css

i am trying to make the control not visable through the css but still the control is been shown.

i tried doing like this

html1.Visible = false;

but this creates an gap in the menu where is been 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 the gap there how can we achive this. any help on this would be great

Upvotes: 6

Views: 6197

Answers (3)

Arun Prasad E S
Arun Prasad E S

Reputation: 10115

You can attach this class to button using above methods Very helpful when the button is taking the space , which it shouldn't be

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

Upvotes: 0

Gaurav Agrawal
Gaurav Agrawal

Reputation: 4431

If you want to add more than one property in style element in that case use Style property instead of Attributes property like this example....

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

Upvotes: 1

the_joric
the_joric

Reputation: 12226

You just need to use style instead of class:

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

You may also consider the option of making a CSS style like:

.hidden
{
   display:none;
}

And then apply it via 'class':

html1.Attributes.Add("class", "hidden");

Upvotes: 9

Related Questions