Repeater Control and ViewState Problems

H

Harry

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
 
B

bruce barker

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

-- bruce (sqlwork.com)



| 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
|
|
 
H

Harry

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
 
H

Harry

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
 

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

Similar Threads

repeater 0
ViewState and Repeater Control 1
repeater eval problem 2
ViewState? 1
Repeater control 1
Repeater control and Eval() 7
Problems with Repeater control 0
LinkButton in Repeater control 5

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top