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

Transfer and Delete event

2 Answers 235 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Luigi Gaeta
Top achievements
Rank 1
Luigi Gaeta asked on 17 Dec 2009, 01:03 PM
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 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 17 Dec 2009, 04:58 PM
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.
0
Simon
Telerik team
answered on 19 Dec 2009, 10:14 AM
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.
Tags
ListBox
Asked by
Luigi Gaeta
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Simon
Telerik team
Share this question
or