locked
Best way to hide controls? RRS feed

  • Question

  • User2108892867 posted

    Hello everyone, I have read some article talking about "display:none" in css. I have tried to applied this on an asp.net label control. It is working ok. However, when I viewed html source by using inspect element in Firefox. I still can see the label in the html tag. Is there a way I could completely hide this?

    Many articles have explained that "display:none;" is not a good practice. Some said that it all depends on the real purposes of hiding the controls. For me, I use the label to carry some string that I can make use later. Any suggestion what is the best way?

    Thanks. 

    Monday, December 10, 2012 5:00 PM

Answers

  • User-2010311731 posted

    If you don't want the label to render into the HTML, you can set the visibility from your code-behind...

    Label1.Visible = false;

    Matt

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2012 5:45 PM
  • User348806598 posted

    Hi,

    If information in the label is critical information. I will suggest you not to use label for this, you can use session to store such information. If the information is not sensitive then there is no problem using display:none. display:none simply hides the control from viewing but its present in the dom and you can view the control using firebug or ie developer tool. If you set visible=false, the control will not render in the dom at all.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2012 11:05 PM
  • User-179079940 posted

    controlname.visible=false

    or

    use panel in which put control and use hide ans show panel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 11, 2012 1:04 AM

All replies

  • User-2010311731 posted

    If you don't want the label to render into the HTML, you can set the visibility from your code-behind...

    Label1.Visible = false;

    Matt

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2012 5:45 PM
  • User2108892867 posted

    Hello AZMatt, thanks for the suggestion. Do you think there is a better way to do this like using css? So I can change it back to visible in the CSS if it happens that I need to do so.

    Thanks. 

    Monday, December 10, 2012 8:16 PM
  • User348806598 posted

    Hi,

    If information in the label is critical information. I will suggest you not to use label for this, you can use session to store such information. If the information is not sensitive then there is no problem using display:none. display:none simply hides the control from viewing but its present in the dom and you can view the control using firebug or ie developer tool. If you set visible=false, the control will not render in the dom at all.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2012 11:05 PM
  • User527778624 posted

    Hi,

    To stop visible of label in view-source, u can use UpdatePanel and render label via partial-postback (not in full postback)

    or with clientside solution: use javascript to dynamically create it and add to DOM.

    (assuming user is not using debug tools: firebug or dev toosl).

    Tuesday, December 11, 2012 12:53 AM
  • User-1604169926 posted

    Do you think there is a better way to do this like using css? So I can change it back to visible in the CSS if it happens that I need to do so.

    If your label contains not much confidential information and if you want it to re-visible again, you can do it simply by jquery

    hide() and show() functions.

    e.g.

    $(document).ready(function(){
       $(".label").show(); //will make your label visible
       $(".label").hide(); //will make it invisible again
    });



    Tuesday, December 11, 2012 1:03 AM
  • User-179079940 posted

    controlname.visible=false

    or

    use panel in which put control and use hide ans show panel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 11, 2012 1:04 AM
  • User-654786183 posted

    Hiding a control client side and server side has its own advantages and disadvantages. 

    If you are hiding a control (Server or HTML control) from server side, it will not be rendered in the markup and you cannot access that control using JavaScript/jQuery.  This is more safe but it depends on your requirement.

    If you still want to access the control with jQuery/JavaScript after rendering, go with CSS for hiding.  But there is a risk of exposing data as this is viewable with Firebug or IE Developer tools or by simply see the HTML markup.

     

    Tuesday, December 11, 2012 1:04 AM
  • User2108892867 posted

    Hello everyone, thanks for all the replies. I now go the hard way by setting visible="false". Will have to come back and look into this more when I finish the main functionalities. 

    Regards;

    Wednesday, December 12, 2012 5:21 PM