Reputation: 3526
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" >
Dir.Área: </td>
</div>
<div id="DirBaDiv1" runat="server" visible="false">
<td class="heading4" align="left" style="width: 21%" id="DirCoordDiv_Text" runat="server" >
Dir.Coord.: </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...
Upvotes: 3
Views: 25450
Reputation: 147
I have had a similar problem, where I could not set a div
element visible (divSomeName.Visible=true;)
, which puzzled me for a while. Then, I found out that the reason why was in the parent element, which Visible
property was set to false
. I resolved my problem by moving the div
element out of the invisible parent.
Upvotes: 0
Reputation: 19797
Realizing this is a really old question...
First, the HTML is horribly broken, you can't have a div
as a parent of a td
.
Second, check the OnPageLoad
event is not setting the combobox and therefore changing the selected value. Any initialization should take place inside if(!IsPostback){/*Do Your Stuff here*/}
I'm going to set the text of a literal control, this will ensure no additional HTML is rendered to the page. Note there are no div
and only one td
. This is a good thing! Alternatively you could just set the innerText
or innerHtml
of the TD directly
ASPX
<td class="heading4" align="left" style="width: 21%" id="DirLoc_Text" runat="server" >
<asp:Literal runat="server" id="litLocText" />:
</td>
C# Code Behind in the Combobox event handler
litLocText.Text = comboBox.value == [your condition] ? "Dir.Área" : "Dir.Coord";
Upvotes: 1
Reputation: 11
<div runat="server" visible='<%# (Eval(condition)) ? true : false %>'></div>
that works for me
Upvotes: 1
Reputation: 4101
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
Upvotes: 4