This is a migrated thread and some comments may be shown as answers.

ItemCreated getting called continuously..?

3 Answers 30 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Andrew Galea
Top achievements
Rank 1
Andrew Galea asked on 12 Jan 2012, 11:04 AM
I am using the ItemCreated event to retrieve a logo from the database for any items that are added to it.  The code also updates a "Point Total" for the items in the ListBox once the new item has been created.  This all is working fine.

However when I step through the code I find that the ItemCreated method is getting called for all existing items in the ListBox as well as the newly added one.  To make it worse it seems the ItemCreated method is called for every existing item in the ListBox whenever the SelectedIndexChanged event is raised as well.  Is this normal behaviour?

Here is my ItemCreated code snippet:

protected void listEntity_ItemCreated(object sender, RadListBoxItemEventArgs e)
        {
            RadListBox listBox = (RadListBox)sender;
 
            RadListBoxItem item = e.Item;
 
            LMEntityEntity entity = new LMEntityEntity(int.Parse(item.Value));
 
            RadBinaryImage entityLogo = (RadBinaryImage)item.FindControl("entityLogo");
            if (entity.Logo.Length > 0)
                entityLogo.DataValue = entity.Logo;
            else
                entityLogo.ImageUrl = "~/images/faction-icons/" + _factionName.ToLower() + ".jpg";
            item.DataBind();
 
            UpdatePointTotal(listBox);
        }

And here is my ListBox declaration in the HTML:

<telerik:RadListBox ID="upgradesListBox" runat="server" width="400px" DataKeyField="LMEntityIdChild"
                                Height="170px" CssClass="list-box" Skin="Black" AllowDelete="False" DataValueField="LMEntityIdChild"
                                AllowTransfer="True" TransferToID="listEntityListBox"
                                AutoPostBack="false" AllowReorder="False"
                                onitemdatabound="upgrades_ItemDataBound" AllowTransferDuplicates="True"
                                AllowTransferOnDoubleClick="True" AutoPostBackOnTransfer="True"
                                ontransferring="upgrades_Transferring" TransferMode="Copy">
                                <ItemTemplate>
                                    <telerik:RadBinaryImage id="logoImage" runat="server" CssClass="list-box-icon"
                                        DataValue='<%# (int)(Eval("LMEntity.Logo.Length"))>0?Eval("LMEntity.Logo"):null %>' height="20px" ResizeMode="Fit" width="20px" />
                                    <span class="list-box-text"><asp:Label ID="itemLabel" runat="server"></asp:Label></span>
                                </ItemTemplate>               
                                <ButtonSettings ShowTransferAll="False" TransferButtons="TransferFrom" />
                            </telerik:RadListBox>

Regards,
Andrew

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 12 Jan 2012, 03:07 PM
Hello Andrew,

The ItemCreated event occurs for each new item that is added to the Items collection of the RadListBox.

The following help document explains more on this.
ItemCreated.

Thanks,
Princy.
0
Chris
Top achievements
Rank 1
answered on 12 Feb 2012, 05:57 AM
I'm also noticing this issue. The support page mentioned above does not address the issue. I think OnItemCreated should only be fired when a new item is added to the ListBox, not for every item already in the ListBox on every postback. Is another event I should be using?

Thanks,
Chris
0
Peter Filipov
Telerik team
answered on 16 Feb 2012, 10:18 AM
Hi Chris,

RadListBox supports only ItemCreated event which is fire for each item. There is no event that is fired only for the newly created items.

All the best,
Peter Filipov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
ListBox
Asked by
Andrew Galea
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Peter Filipov
Telerik team
Share this question
or