473,405 Members | 2,210 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,405 software developers and data experts.

Repeater ItemCreated vs ItemDataBound

Hi. Can anyone explain why, when setting the Text of a Label control in the ItemCreated event of a Repeater (example below), the Text value is NOT persisted to ViewState? I know this can be fixed by using the ItemDataBound event, but I don't understand why.

here's a page snippet:

<asp:Repeater runat="server" id="myRepeater"
OnItemCreated="myRepeater_ItemCreated">
...
<ItemTemplate><tr><td><asp:Label id="myLabel" runat="server" /></td></tr></ItemTemplate>
...
</asp:Repeater>

and here's a simple ItemCreated event:

protected void myRepeater_ItemCreated(object sender, RepeaterItemEventArgs
e)
{
foreach(Control ctrl in e.Item.Controls)
{
if(ctrl is Label)
{
DataRowView r=(DataRowView)e.Item.DataItem;
((Label)ctrl).Text=r["MY_FIELD"].ToString();
}
}
}

Thanks

KH
Nov 18 '05 #1
2 12308
Hi,

because in ItemCreated RepeaterItem is not yet added to Repeaters
Controls/Items collection, which means its child controls are neither.
Generally, Control lifecycle (Begin ViewState tracking is one phase in the
lifecycle) starts after Control is added to the Controls collection. So it
means state is tracked & saved for the changes made *after* control is added
to the Controls collection.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


"Kevin Hector" <an*******@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Hi. Can anyone explain why, when setting the Text of a Label control in the
ItemCreated event of a Repeater (example below), the Text value is NOT
persisted to ViewState? I know this can be fixed by using the ItemDataBound
event, but I don't understand why.

here's a page snippet:

<asp:Repeater runat="server" id="myRepeater"
OnItemCreated="myRepeater_ItemCreated">
...
<ItemTemplate><tr><td><asp:Label id="myLabel" runat="server"
/></td></tr></ItemTemplate>
...
</asp:Repeater>

and here's a simple ItemCreated event:

protected void myRepeater_ItemCreated(object sender, RepeaterItemEventArgs
e)
{
foreach(Control ctrl in e.Item.Controls)
{
if(ctrl is Label)
{
DataRowView r=(DataRowView)e.Item.DataItem;
((Label)ctrl).Text=r["MY_FIELD"].ToString();
}
}
}

Thanks

KH

Nov 18 '05 #2
Hi,

because in ItemCreated RepeaterItem is not yet added to Repeaters
Controls/Items collection, which means its child controls are neither.
Generally, Control lifecycle (Begin ViewState tracking is one phase in the
lifecycle) starts after Control is added to the Controls collection. So it
means state is tracked & saved for the changes made *after* control is added
to the Controls collection.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


"Kevin Hector" <an*******@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Hi. Can anyone explain why, when setting the Text of a Label control in the
ItemCreated event of a Repeater (example below), the Text value is NOT
persisted to ViewState? I know this can be fixed by using the ItemDataBound
event, but I don't understand why.

here's a page snippet:

<asp:Repeater runat="server" id="myRepeater"
OnItemCreated="myRepeater_ItemCreated">
...
<ItemTemplate><tr><td><asp:Label id="myLabel" runat="server"
/></td></tr></ItemTemplate>
...
</asp:Repeater>

and here's a simple ItemCreated event:

protected void myRepeater_ItemCreated(object sender, RepeaterItemEventArgs
e)
{
foreach(Control ctrl in e.Item.Controls)
{
if(ctrl is Label)
{
DataRowView r=(DataRowView)e.Item.DataItem;
((Label)ctrl).Text=r["MY_FIELD"].ToString();
}
}
}

Thanks

KH

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kevin Hector | last post by:
Hi. Can anyone explain why, when setting the Text of a Label control in the ItemCreated event of a Repeater (example below), the Text value is NOT persisted to ViewState? I know this can be fixed by...
1
by: slaforge | last post by:
I am trying use a repeater to process through the results of a sql query and produce a table that may or may not have multiple rows per record in the query, depending upon whether the technicians...
2
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple...
2
by: Mick | last post by:
Hi, just wanna know if it's possible to get access to my several label controls of my repeater's headertemplate in order to set their Text property ? Thks for help-
3
by: jason.gladstone | last post by:
Hello - I am trying to create a repeater control that contains a dropdownlist. A friend of mine sent me a sample in C#. I am trying to duplicate the sample in VB. This is the C# code in the...
2
by: Philippe Camus | last post by:
I didn't find any documentation about this behaviour. On postbacks the Repeater ItemCreated event is fired before Page_Load event It occurs for each item with empty...
1
by: RicercatoreSbadato | last post by:
I've put an ImageButton control in a repeater. I've set the 'OnItemBound' event of the repeater. Why when I click on the ImageButton it doesn't work? What else I have to do ?
5
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ...
2
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post by:
Hi I have a repeater control as shown below. The Itemtemplate contains a table with linkbuttons in each column of the row. However I wish to change the stlyle of the link button to...
12
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.