Label within repeater losing text on post back

Discussion in 'ASP .Net' started by Kevin Cunningham, Jan 20, 2005.

  1. 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
    Kevin Cunningham, Jan 20, 2005
    #1
    1. Advertising

  2. Kevin,

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

    Eliyahu

    "Kevin Cunningham" <> wrote in message
    news:uQUcXbq$...
    > 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
    >
    >
    Eliyahu Goldin, Jan 20, 2005
    #2
    1. Advertising

  3. Kevin Cunningham

    Kevin C Guest

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

    "Eliyahu Goldin" <> wrote in message
    news:OtxiGKt$...
    > Kevin,
    >
    > Visible=False causes controls not to be sent to client. You can make
    > controls invisible with css rule display:none.
    >
    > Eliyahu
    >
    > "Kevin Cunningham" <> wrote in message
    > news:uQUcXbq$...
    > > 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
    > >
    > >

    >
    >
    Kevin C, Jan 20, 2005
    #3
  4. I thing it is because Label Text is not a part of the viewstate. You have to
    rebind it every time.

    Eliyahu

    "Kevin C" <> wrote in message
    news:e0dFXvv$...
    > Gotcha, but still even when I turn it to visible it doesnt hold the .Text
    > value. Other controls work fine.
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:OtxiGKt$...
    > > Kevin,
    > >
    > > Visible=False causes controls not to be sent to client. You can make
    > > controls invisible with css rule display:none.
    > >
    > > Eliyahu
    > >
    > > "Kevin Cunningham" <> wrote in message
    > > news:uQUcXbq$...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
    Eliyahu Goldin, Jan 20, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3JpZGhhcg==?=

    textbox in user control losing values during post back

    =?Utf-8?B?U3JpZGhhcg==?=, Aug 23, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,489
    =?Utf-8?B?U3JpZGhhcg==?=
    Aug 23, 2006
  2. Michael Lang
    Replies:
    12
    Views:
    888
    Michael Lang
    Dec 29, 2006
  3. =?Utf-8?B?Z29yaWxsYQ==?=
    Replies:
    1
    Views:
    744
    Masudur
    May 25, 2007
  4. Jason C
    Replies:
    4
    Views:
    665
    Morty Abzug
    Jun 26, 2012
  5. Knut Krueger
    Replies:
    8
    Views:
    238
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page