关于可见=假和显示问题:无; [英] Question regarding Visible=false and display:none;

查看:99
本文介绍了关于可见=假和显示问题:无;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我设置一些控件的属性Visible =false时,我不能看到我的aspx页面生成的HTML控件。但是当我使用显示:无风格标记该控件,我看到作为HTML灰色控制。这是为什么?

另外,如果我发现不需要在页面上了一定的控制: -


  1. 应该从我的页面注释掉?

  2. 我应该设置其属性Visible = FALSE

  3. 我应该设置显示:无

什么是牢记时间限制和页面的沉重感的最佳方法?

下面是那是我测试页生成的HTML: -

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/ XHTML1-transitional.dtd>
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
< HEAD>
<标题> < /标题>
< /头>
<身体GT;
<表ID =form1的行动=testvisibility.aspx方法=后NAME =form1的>
< D​​IV>
<输入ID =__ VIEWSTATE类型=隐藏 value=\"/wEPDwUKMTY2NDk3NDQzNQ9kFgICAw9kFgQCBw8PFgIeB1Zpc2libGVoZGQCCQ8WAh4Fc3R5bGUFDWRpc3BsYXk6bm9uZTtkZEjYzMWMovvrGmuSrQHwc5ZXgqXCrf+lekz1GgsdjUd+\" NAME =__ VIEWSTATE>
< / DIV>
< D​​IV>
visiblelabel ::
&所述;跨度的id =visiblelabel> visiblelabel&下; /跨度>
< BR>
labelwithvisiblefalseonaspx ::
< BR>
labelwithdisplaynoneonaspx ::
< D​​IV的风格=显示:无;>
&所述;跨度的id =labelwithdisplaynoneonaspx> labelwithdisplaynoneonaspx&下; /跨度>
< / DIV>
< BR>
labelwithvisiblefalseonserverside ::
< BR>
labelwithdisplaynoneonserverside ::
< D​​IV ID =divforlabelwithdisplaynoneonserverside的风格=显示:无;>
&所述;跨度的id =labelwithdisplaynoneonserverside> labelwithdisplaynoneonserverside&下; /跨度>
< / DIV>
< BR>
< / DIV>
< /表及GT;
< /身体GT;
< / HTML>


解决方案

如果要动态显示或通过Ajax的/ etc隐藏控制,或者控制包含的信息你的页面需要设置显示:无在CSS

如果你不希望呈现控件在所有的在某些情况下的设置可见=假。由于它保持控件的HTML页面输出的内容,它使略小页面 - 但如果你想显示通过Ajax的/ etc控制,这是不行的。

如果你不希望呈现控件可言,时期的,不要把它注释掉 - 完全删除。所有的控制,可见或不可见,仍然需要处理,所以可见=假在浪费CPU(和可能导致的副作用)如果你从来没有打算呈现控件。而你真的不希望大量的注释掉的东西飘来飘去;它只是让维修困难。您可以随时拿回来从你的版本控制,如果你发现你以后需要它。 (您的的使用SVN / GIT中/ CVS /的的东西的吧?)

If I set some control's property Visible="false", I cant see the control in the HTML generated of my aspx page. But when I use display:none in style tag for that control, I see the control as greyed out in the HTML. Why is that?

Also, If I find some control that is not needed on the page anymore:-

  1. should I comment it out from my page?
  2. Should I set its property Visible=false"
  3. Should I set display:none?

What would be the best approach keeping in mind the time constraint and page's heaviness?

Below is the HTML that was generated of my test page:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
</head>
<body>
<form id="form1" action="testvisibility.aspx" method="post" name="form1">
<div>
<input id="__VIEWSTATE" type="hidden" value="/wEPDwUKMTY2NDk3NDQzNQ9kFgICAw9kFgQCBw8PFgIeB1Zpc2libGVoZGQCCQ8WAh4Fc3R5bGUFDWRpc3BsYXk6bm9uZTtkZEjYzMWMovvrGmuSrQHwc5ZXgqXCrf+lekz1GgsdjUd+" name="__VIEWSTATE">
</div>
<div>
visiblelabel::
<span id="visiblelabel">visiblelabel</span>
<br>
labelwithvisiblefalseonaspx::
<br>
labelwithdisplaynoneonaspx::
<div style="display: none;">
<span id="labelwithdisplaynoneonaspx">labelwithdisplaynoneonaspx</span>
</div>
<br>
labelwithvisiblefalseonserverside::
<br>
labelwithdisplaynoneonserverside::
<div id="divforlabelwithdisplaynoneonserverside" style="display: none;">
<span id="labelwithdisplaynoneonserverside">labelwithdisplaynoneonserverside</span>
</div>
<br>
</div>
</form>
</body>
</html>

解决方案

If you want to dynamically show or hide the control via Ajax/etc, or if the control contains information your page needs, set display:none in CSS.

If you don't want to render the control at all in certain situations, set Visible="false". Since it keeps the control's HTML out of the page, it makes for slightly smaller pages -- but if you want to show the control via Ajax/etc, this won't work.

If you don't want to render the control at all, period, don't comment it out -- remove it altogether. All controls, visible or not, still require processing, so Visible=false is wasting CPU (and possibly causing side effects) if you never intend to render the control. And you really don't want lots of commented-out stuff floating around; it just makes maintenance harder. You can always get it back from your revision control if you find you do need it later. (You are using SVN/Git/CVS/something, right?)

这篇关于关于可见=假和显示问题:无;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆