By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

Repeater Control and ViewState Problems

P: n/a
Hello,
I have a Repeater control that contains a Label control inside its
ItemTemplate. A dummy mockup of the HTML code looks as follows:

<asp:repeater id="StyleRepeater" Runat="server">
<ItemTemplate>
<asp:Label ID="ClassLabel" Runat="server">
<... various other ASP.NET Web Controls ...>
</ItemTemplate>
</asp:repeater>

In the code behind for this page, I handle the Repeater's ItemCreated event
to initially set the text of the label. This works perfectly, however, when
a postback occurs and Repeater data is fetched from the ViewState and all my
Web Controls repopulate correctly, except for the Label, which is set to the
empty string (i.e. ""). Since my other controls in the Repeater
(DropDownLists, CheckBoxes, etc.) are being correctly repopulated on
postback from the ViewState, it leads me to believe that there is some
specific problem with saving the Label's ViewState. I tried manually
enabling the ViewState on the label control (i.e. <asp:Label ID="ClassLabel"
EnableViewState="True" Runat="server">), but that had no effect. Any advice
would be much appreciated.

- Harry
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
label don't post data back, or save their html content in viewstate - you
must reset them on postback.

-- bruce (sqlwork.com)

"Harry" <ro******@vu.union.edu> wrote in message
news:OT**************@TK2MSFTNGP14.phx.gbl...
| Hello,
| I have a Repeater control that contains a Label control inside its
| ItemTemplate. A dummy mockup of the HTML code looks as follows:
|
| <asp:repeater id="StyleRepeater" Runat="server">
| <ItemTemplate>
| <asp:Label ID="ClassLabel" Runat="server">
| <... various other ASP.NET Web Controls ...>
| </ItemTemplate>
| </asp:repeater>
|
| In the code behind for this page, I handle the Repeater's ItemCreated
event
| to initially set the text of the label. This works perfectly, however,
when
| a postback occurs and Repeater data is fetched from the ViewState and all
my
| Web Controls repopulate correctly, except for the Label, which is set to
the
| empty string (i.e. ""). Since my other controls in the Repeater
| (DropDownLists, CheckBoxes, etc.) are being correctly repopulated on
| postback from the ViewState, it leads me to believe that there is some
| specific problem with saving the Label's ViewState. I tried manually
| enabling the ViewState on the label control (i.e. <asp:Label
ID="ClassLabel"
| EnableViewState="True" Runat="server">), but that had no effect. Any
advice
| would be much appreciated.
|
| - Harry
|
|
Nov 19 '05 #2

P: n/a
Bruce,
The Text property of the Label isn't being changed client side by
JavaScript, rather serverside by C# code, hence posting back information
from the client to the server has nothing to do with my problem.
Furthermore, the Label has a ViewState property which should be used to
repopulate the Text property among other things.

For example if one had a Label with its initial Text property set to
"Create:" and in their Page_Load method one had the following:

if (!IsPostBack)
{
MyLabel.Text = "Update:";
}

You would see that MyLabel.Text = "Update:"; gets called exactly once when
the page initially loads. All subsequent postbacks to the page wouldn't hit
this piece of code, yet the Label would remember that it's Text property is
set to "Update:", rather then "Create:"

- Harry

"bruce barker" <no***********@safeco.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
label don't post data back, or save their html content in viewstate - you
must reset them on postback.

-- bruce (sqlwork.com)

"Harry" <ro******@vu.union.edu> wrote in message
news:OT**************@TK2MSFTNGP14.phx.gbl...
| Hello,
| I have a Repeater control that contains a Label control inside its
| ItemTemplate. A dummy mockup of the HTML code looks as follows:
|
| <asp:repeater id="StyleRepeater" Runat="server">
| <ItemTemplate>
| <asp:Label ID="ClassLabel" Runat="server">
| <... various other ASP.NET Web Controls ...>
| </ItemTemplate>
| </asp:repeater>
|
| In the code behind for this page, I handle the Repeater's ItemCreated
event
| to initially set the text of the label. This works perfectly, however,
when
| a postback occurs and Repeater data is fetched from the ViewState and all my
| Web Controls repopulate correctly, except for the Label, which is set to
the
| empty string (i.e. ""). Since my other controls in the Repeater
| (DropDownLists, CheckBoxes, etc.) are being correctly repopulated on
| postback from the ViewState, it leads me to believe that there is some
| specific problem with saving the Label's ViewState. I tried manually
| enabling the ViewState on the label control (i.e. <asp:Label
ID="ClassLabel"
| EnableViewState="True" Runat="server">), but that had no effect. Any
advice
| would be much appreciated.
|
| - Harry
|
|

Nov 19 '05 #3

P: n/a
Bruce,
The Text property of the Label isn't being changed client side by
JavaScript, rather serverside by C# code, hence posting back information
from the client to the server has nothing to do with my problem.
Furthermore, the Label has a ViewState property which should be used to
repopulate the Text property among other things.

For example if one had a Label with its initial Text property set to
"Create:" and in their Page_Load method one had the following:

if (!IsPostBack)
{
MyLabel.Text = "Update:";
}

You would see that MyLabel.Text = "Update:"; gets called exactly once when
the page initially loads. All subsequent postbacks to the page wouldn't hit
this piece of code, yet the Label would remember that it's Text property is
set to "Update:", rather then "Create:"

- Harry

"bruce barker" <no***********@safeco.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
label don't post data back, or save their html content in viewstate - you
must reset them on postback.

-- bruce (sqlwork.com)

"Harry" <ro******@vu.union.edu> wrote in message
news:OT**************@TK2MSFTNGP14.phx.gbl...
| Hello,
| I have a Repeater control that contains a Label control inside its
| ItemTemplate. A dummy mockup of the HTML code looks as follows:
|
| <asp:repeater id="StyleRepeater" Runat="server">
| <ItemTemplate>
| <asp:Label ID="ClassLabel" Runat="server">
| <... various other ASP.NET Web Controls ...>
| </ItemTemplate>
| </asp:repeater>
|
| In the code behind for this page, I handle the Repeater's ItemCreated
event
| to initially set the text of the label. This works perfectly, however,
when
| a postback occurs and Repeater data is fetched from the ViewState and all my
| Web Controls repopulate correctly, except for the Label, which is set to
the
| empty string (i.e. ""). Since my other controls in the Repeater
| (DropDownLists, CheckBoxes, etc.) are being correctly repopulated on
| postback from the ViewState, it leads me to believe that there is some
| specific problem with saving the Label's ViewState. I tried manually
| enabling the ViewState on the label control (i.e. <asp:Label
ID="ClassLabel"
| EnableViewState="True" Runat="server">), but that had no effect. Any
advice
| would be much appreciated.
|
| - Harry
|
|


Nov 19 '05 #4

P: 1
Harry,

This might not help, but in creating a composite control, you must add the child control the composite controls Controls collection before setting the Text property of the label.

If you do not do this, then the data will not be restored on post back.

Elia
Apr 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.