ItemCreated getting called continuously..?

4 posts, 0 answers
  1. Andrew Galea
    Andrew Galea avatar
    22 posts
    Member since:
    Nov 2009

    Posted 12 Jan 2012 Link to this post

    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;
                    entityLogo.ImageUrl = "~/images/faction-icons/" + _factionName.ToLower() + ".jpg";

    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">
                                        <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>
                                    <ButtonSettings ShowTransferAll="False" TransferButtons="TransferFrom" />

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Jan 2012 Link to this post

    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.

  3. Chris
    Chris avatar
    3 posts
    Member since:
    Mar 2011

    Posted 11 Feb 2012 Link to this post

    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?

  4. Peter Filipov
    Peter Filipov avatar
    1028 posts

    Posted 16 Feb 2012 Link to this post

    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 >>
Back to Top