简体   繁体   English

使用css隐藏Asp.net中的控件

[英]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. 我试图通过css使控制不可见,但仍然显示控件。

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 对此的任何帮助都会很棒

You just need to use style instead of class : 你只需要使用style而不是class

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

You may also consider the option of making a CSS style like: 您也可以考虑制作CSS样式的选项:

.hidden
{
   display:none;
}

And then apply it via 'class': 然后通过'class'应用它:

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

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.... 如果要在style元素中添加多个属性,请使用Style属性而不是Attributes属性,如此示例....

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

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM