Label within repeater losing text on post back

K

Kevin Cunningham

I have a repeater with some labels in it (code below). For whatever reason
the text for the label is not persisted in viewstate on the postback. Is
there a trick to get this to work? Is there something else I can do to get
the same visual effect (not using a datagrid :) )? This is annnooying!

<table>
<asp:repeater id="rptGunReadingsNew" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Label id="lblGunReadingID" runat="server" Visible="False"
EnableViewState="True" > <%# DataBinder.Eval(Container.DataItem,
"GunReadingID") %> </asp:Label>
</td>
<td>
<asp:Label id="lblDescription" runat="server"
CssClass="LargerMaroon" EnableViewState="True"> <%#
DataBinder.Eval(Container.DataItem, "Description") %> </asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
</table>

On the post back I am trying to do this ... and the text value is "".


foreach ( RepeaterItem item in rptGunReadingsNew.Items ) {
object o1 = item.FindControl( "lblGunReadingID" );
object o2 = item.FindControl( "lblDescription" );
}


Thanks,
Kevin
 
E

Eliyahu Goldin

Kevin,

Visible=False causes controls not to be sent to client. You can make
controls invisible with css rule display:none.

Eliyahu
 
K

Kevin C

Gotcha, but still even when I turn it to visible it doesnt hold the .Text
value. Other controls work fine.
 
E

Eliyahu Goldin

I thing it is because Label Text is not a part of the viewstate. You have to
rebind it every time.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top