Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding <div> from vb.net code side

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?

like image 680
reffe Avatar asked Apr 22 '10 21:04

reffe


People also ask

How to hide div tag in vb net?

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.

How to hide div class in vb net?

myDiv. Visible = False 'Hide the div. myDiv. Visible = True 'Show the div.

How do I completely hide a div?

The document. getElementById will select the div with given id. The style. display = "none" will make it disappear when clicked on div.

How do I hide a div but keep the space?

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.


1 Answers

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
like image 180
AaronSieb Avatar answered Sep 20 '22 01:09

AaronSieb