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

Prevent Deletion of RadListBoxItem

1 Answer 93 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
G.
Top achievements
Rank 1
G. asked on 20 Jan 2012, 05:42 PM
Hello,

Telerik.Web.UI Version 2010.3.1317.35

I have 2 RadListBox controls defined as follows:

 

 

<div id="dFieldSelection" style="padding:5px;" runat="server">

 

 

 

<telerik:radlistbox runat="server" DataTextField="Name" DataValueField="FieldID" ID="radListBox_1" AllowDelete="True"

 

 

 

AllowReorder="True" AllowTransfer="True" AutoPostBackOnTransfer="true" AutoPostBackOnDelete="true" TransferToID="radListBox_2">

 

 

 

</telerik:radlistbox>

 

 

 

<telerik:radlistbox runat="server" ID="radListBox_2"

 

 

 

AutoPostBackOnTransfer="true" AutoPostBackOnDelete="true"

 

 

 

ondeleting="radListBox_2_Deleting"></telerik:radlistbox>

 

 

 

</div>

I programmtically place some mandatory fields into radListBox_2...  my goal is to prevent a user from deleting these mandatory items from radListBox_2 (i.e. I have noticed that the radListBox_2_Deleting server side event get executed when the user presses the arrow button to transfer an item back to radListBox_1).

Inside of radListBox_2_Deleting server side event I simply do some code checks and if this is a mandtory item I set e.Cancel = true... hoping that that will cancel the deletion.  However, this does not appear to work as I expected.

How can I prevent a user from moving 1 RadListBoxItem from radListBox_2 back into radListBox_1?

Thx in advance!!!

 

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 23 Jan 2012, 12:57 PM
Hello Gerald,

You can use the OnClientTransferring event and check if the source listbox is the one you don't want to delete from. If it is, then you can use args.set_cancel(true) to cancel the transfer. Here's an example:
function clientTransferring(sender, args) {
    var listbox = $find("<%= radListBox_2.ClientID %>");
    if(args.get_sourceListBox() == listbox)
        args.set_cancel(true);
}

 
All the best,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
ListBox
Asked by
G.
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or