Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ListBox > ItemCreated getting called continuously..?

Not answered ItemCreated getting called continuously..?

Feed from this thread
  • Andrew Galea avatar

    Posted on Jan 12, 2012 (permalink)

    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

    Reply

  • Posted on Jan 12, 2012 (permalink)

    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.

    Reply

  • Chris avatar

    Posted on Feb 11, 2012 (permalink)

    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

    Reply

  • Peter Filipov Peter Filipov admin's avatar

    Posted on Feb 16, 2012 (permalink)

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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ListBox > ItemCreated getting called continuously..?