I have this code for hiding a table and a cell in aspx, backend vb.net. Code -
For Each row As HtmlTableRow In tab_a1.Rows
If row.ID = "a1" Then
For Each cell As HtmlTableCell In row.Cells
cell.Visible = (cell.ID = "a1")
Next
ElseIf row.ID = "b1" Then
For Each cell As HtmlTableCell In row.Cells
cell.Visible = (cell.ID = "b1")
Next
Else
row.Visible = False
End If
Next
Now instead of tables I'm using <div>
tags. How can I use similar code and make div's visible and invisible?
You can hide (not render) SCRIPT tags by wrapping them in a DIV tag, making that runat="server", then setting its visible property to false in the code-behind. As already adequately explained in solution 1, posted in 2011. And mentioned again in solution 3, also from 2011. And mentioned again in solution 5 from 2014.
myDiv. Visible = False 'Hide the div. myDiv. Visible = True 'Show the div.
The document. getElementById will select the div with given id. The style. display = "none" will make it disappear when clicked on div.
The visibility: hidden rule, on the other hand, hides an element, but the element will still take up space on the web page. If you want to hide an element but keep that element's space on the web page, using the visibility: hidden; rule is best.
Add runat="server"
and an ID to your div. You can then hide the div using its Visible
property.
Markup:
<div ID="myDiv" runat="server">Test DIV</div>
VB:
myDiv.Visible = False 'Hide the div.
myDiv.Visible = True 'Show the div.
You can loop through child controls using the controls collection:
For Each child As Control In myDiv.Controls
If TypeOf child Is HtmlControl Then
Dim typedChild As HtmlControl = CType(child, HtmlControl)
'Search grandchildren, toggle visibility, etc.
End If
Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With