Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding a control in Asp.net using css

Tags:

c#

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

like image 569
happysmile Avatar asked Feb 09 '12 12:02

happysmile


2 Answers

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");
like image 56
the_joric Avatar answered Oct 14 '22 08:10

the_joric


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");
like image 23
Gaurav Agrawal Avatar answered Oct 14 '22 08:10

Gaurav Agrawal