Hiding a label

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Ross
    New Member
    • Jan 2007
    • 119

    #1

    Hiding a label

    I want a hidden label on my page that becomes visible if cookies are not enabled.
    Now I have javascript to test cookie and change the labels visibility property, but If I set the label to not visible in .net then it does not build the label at all. I have to use an asp:label (instead of a normal html label) because of translation issues.

    Is there a way I can get it to build a label and not show until javascript changes something?
  • chazcross
    New Member
    • Feb 2007
    • 31

    #2
    Then dont hide the label in .net
    use inline css
    add this tag to the label

    style="display: none;"


    and then use js to change it to display:block

    Code:
    document.getElementById("elementnamehere").style.display = "block";

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Hi there!

      Chazcross is right.

      When you hide a label using the server side code in .NET, the element is never written to the page (thus it is more than invisible, its not there).

      By setting the label's "style=display: none" instead, the label is still present on the web page but simply isn't displayed. Then when your JavaScript detects that your Cookies are disabled you can just set the label's style to be "style=display: block" or inline or whatever you would like.

      When you want to access the label using JavaScript, you can do so by using the following:
      document.getEle mentById('label Name').style.di splay='inline';

      Just remember that if you are using this label for other things (like displaying all of your errors or something), that this variable is invisible by default. You'll have to set the display value back every time you want to use it.

      I'd just keep one label for the Cookies error message and use separate labels for displaying other error messages to avoid this kind of mess.

      Cheers!

      -Frinny

      Comment

      • Bob Ross
        New Member
        • Jan 2007
        • 119

        #4
        I have got it working just the way I want it.

        Thanks very much to the both of you.

        Comment

        Working...