visible = true/false

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karenRoss
    New Member
    • Jun 2007
    • 27

    #1

    visible = true/false

    hi!

    I was wondering if anyone knows of a way to show and hide an asp panel based on a user click on a page.

    Or should I use javascript and CSS tags to show/unshow the table I want?

    I might not know the ID to some of these objects and I think that might be a problem.

    Any thoughts?
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by karenRoss
    hi!

    I was wondering if anyone knows of a way to show and hide an asp panel based on a user click on a page.

    Or should I use javascript and CSS tags to show/unshow the table I want?

    I might not know the ID to some of these objects and I think that might be a problem.

    Any thoughts?
    You can use JavaScript and CSS if you'd like to. Remember that if you set an element in your Server Side code it will simply not write that object to browser. Therefore you can't refer to the object using JavaScript or CSS if you've set something to be visible=false in your Server Side code.

    You can always refer to your asp panel's client id..pass it to your JavaScript to control its CSS properties.

    Eg:
    [code=vbnet]
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
    CheckBoxVisibil itiy.Attributes .Add("OnClick", "SetPanelVisibi lity('" + myPanel.ClientI D + "');")
    ...
    End Sub
    [/code]

    [code=JavaScript]
    <script>
    function SetPanelVisibil ity(nameOfPanel )
    { if(condition... .)
    {
    document.getEle mentByID(nameOf Panel).visible = 'visible'
    }
    }
    </script>

    [/code]

    Hope this helps!

    -Frinny

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Originally posted by Frinavale
      [code=JavaScript]
      <script>
      function SetPanelVisibil ity(nameOfPanel )
      { if(condition... .)
      {
      document.getEle mentByID(nameOf Panel).visible = 'visible'
      }
      }
      </script>
      [/code]
      -Frinny
      Be aware that document.getEle mentByID() is not a universal syntax (firefox/netscape is a little different I think)

      It's recomended to try this instead:
      [code=JavaScript]
      function returnObjById( id )
      {
      if (document.getEl ementById)
      var returnVar = document.getEle mentById(id);
      else if (document.all)
      var returnVar = document.all[id];
      else if (document.layer s)
      var returnVar = document.layers[id];
      return returnVar;
      }
      [/code]

      Comment

      • karenRoss
        New Member
        • Jun 2007
        • 27

        #4
        Thanks for your input guys! It was a big help. I was able to put together some sort of javascript that worked.

        Comment

        Working...