Transfer and Delete event

3 posts, 0 answers
  1. Luigi Gaeta
    Luigi Gaeta avatar
    16 posts
    Member since:
    Jul 2005

    Posted 17 Dec 2009 Link to this post

    Hi guy,
    there's a way to distinguish between transfer event and delete event?
    In my scenario the transferring an item from listBox1 to listBox2 is a simple change of type (white to black), while deleting is remove the item from the application at all.
    My problem is with transfer event, so when I click on the transfer button, the delete event is launched and the item gone to deleted state!
    This is my code:

                            <telerik:RadListBox runat="server" ID="radListMittentiAttendibili"
                                Height="240px"
                                Width="350px"
                                AllowTransfer="true"
                                AutoPostBackOnTransfer="true"
                                TransferToID="radListMittentiBloccati"
                                OnTransferred="radListMittentiAttendibili_Transferred"
                                AllowDelete="true"
                                AutoPostBackOnDelete="true"
                                OnDeleted="radListMittentiAttendibili_Deleted" 
                                SelectionMode="Multiple"
                                DataKeyField="ID"
                                DataTextField="Email"
                                DataValueField="ID"
                            >
                                <ButtonSettings ShowTransferAll="false" ShowReorder="false" VerticalAlign="Middle" ShowDelete="true" />
                            </telerik:RadListBox>
                            <telerik:RadListBox runat="server" ID="radListMittentiBloccati"
                                Height="240px"
                                Width="350px"
                                SelectionMode="Multiple"
                                DataKeyField="ID"
                                DataTextField="Email"
                                DataValueField="ID"
                                AllowDelete="true"
                                AutoPostBackOnDelete="true"
                                OnDeleted="radListMittentiBloccati_Deleted" 
                            >
                                <ButtonSettings ShowTransferAll="false" ShowTransfer="false" ShowReorder="false" Position="Right" VerticalAlign="Middle" ShowDelete="true" />
                            </telerik:RadListBox>

    Give me a solution, please.
  2. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 17 Dec 2009 Link to this post

    Are you looking to just keep the original items in the first RadListBox? This can be achieved through the TransferMode="Copy" setting. Otherwise you can always intercept the Transfer event, cancel it and the events fired after transferring and set up your own transfer function which does exactly what you want. Transferring is as simple as taking the item which is being transferred and add it to the RadListBox of your choice.
  3. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 19 Dec 2009 Link to this post

    Hi Luigi Gaeta,

    The server-side Delete event fires when an Item is deleted as well as when it is Transferred (because it is first deleted in the source ListBox and then transferred to the destination one), so there are no built-in means of distinguishing between the both Delete operations.

    Fortunately the client-side Delete event fires only when an Item is deleted via the Delete button. So you could use this event to raise a flag indicating the meaning of the Delete operation.

    So you could add a HiddenField on your page with a default value of "true":

    <asp:HiddenField ID="RadListBoxSourceIsTransferring" runat="server" Value="true" />

    and handle the client-side Deleting event:

    function onDeleting() {
        $get("RadListBoxSourceIsTransferring").value = "false";
    }

    Finally in the server-side Deleting event handler you will know whether the Item is being Deleted or Transferred:

    protected void RadListBoxSource_Deleting(object sender, RadListBoxDeletingEventArgs e)
    {
        if (!bool.Parse(RadListBoxSourceIsTransferring.Value))
        {
            // Item is being deleted.
     
            RadListBoxSourceIsTransferring.Value = "true";
        }
    }

    Please note that you need to re-set the value of the HiddenField so that the approach works for all subsequent operations.

    All the best,
    Simon
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top