Change Visibility of Divs from Code Behind (ASPX)

TiagoM picture TiagoM · Nov 18, 2013 · Viewed 19.2k times · Source

I have a table in html, and inside that table there are multiple rows 'tr', inside each row there are multiple columns 'td'.

What I need it to change between two td's to show inside a particular row.

I have both of them specified in an aspx file, like the example below.

<div id="DirCaDiv1" runat="server" visible="false"> 
    <td class="heading4" align="left" style="width: 21%" id="DirAreaDiv_Text" runat="server" >
        &nbsp;Dir.Área:&nbsp;</td>
</div>


<div id="DirBaDiv1" runat="server" visible="false">
    <td class="heading4" align="left" style="width: 21%" id="DirCoordDiv_Text" runat="server" >
        &nbsp;Dir.Coord.:&nbsp;</td>
</div>

And in my aspx file I have a combo box event (combobox_changed) that change the visibility of each div. It puts one DirCaDiv1.visible="false" and another one DirBaDiv1.Visible="true"

But I don't know why, it doesn't work, I change the item that is selected on the other combobox that is using the event, and nothing happens...

Answer

Mike Beeler picture Mike Beeler · Nov 18, 2013

Actually it's because the visible property is a bool not a string so instead of using "true" or "false" use DirCaDiv1.Visible = true;

See also

http://msdn.microsoft.com/en-us/library/system.web.ui.control.visible(v=vs.100).aspx