473,416 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Repeater Control and ViewState Problems

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
4 8956
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark Rodseth | last post by:
Hi Is it possible to disable viewstate on a repeater control and still raise an OnItemCommand event? All I want to do is click a button on one of the repeater items, raise and event and capture...
5
by: Martin Dew | last post by:
Having some problems getting a hyperlink object to work in my repeater control, It displays the text I have asked it to for the hyperlink, but it does not act as a link. My repeater code is below...
0
by: BryanS | last post by:
I am having trouble trying to link 2 drop down lists and a repeater control. What i want is 2 drop down lists, the first being a list of food categories. When a category is selected the second...
1
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
5
by: Imran Aziz | last post by:
Hello all, I am populating the contents of a repeater control using a database query. In the repeater control I have a link , which I want to display or not based on the current logged in user....
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
2
by: Andy Fish | last post by:
Hi, I have a forrm with viewstate disabled (to try and optimize network performance). I have come a bit unstuck though when I use a repeater with a textbox inside it Obivously with viewstate...
0
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
1
markrawlingson
by: markrawlingson | last post by:
Hello, For starters: Yes, I am new to asp.net, however I hold a good 9-10 years of experience working with classic asp and am only just now upgrading my skills. I'm picking asp.net up pretty...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.