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

Confirm popup on selected index change

2 Answers 92 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 24 Jun 2010, 08:17 PM

I have a simple RadComboBox with a few items in it.  I have AutoPostBack="true" and am implementing the OnSelectedIndexChanged event in the code behind.

What I want to do is:
    If the user selects a certain value in the dropdown, pop up a javascript warning message that allows the user to cancel the change. (like Confirm("Are you sure?");)

My problem is if I use OnClientSelectedIndexChanging, I don't have access to the NEW selected value.  And in OnClientSelectingIndexChanged, I don't have a way to cancel the change (if they choose Cancel in the popup)

Is there any way to accomplish this?

Thanks,
Justin

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 25 Jun 2010, 06:43 AM
Hello Justin,

The following code example will ne helpful for you.

aspx:
 
<telerik:RadComboBox ID="RadComboBox5" runat="server" OnClientSelectedIndexChanging="OnClientSelectedIndexChanging"
    <Items> 
        <telerik:RadComboBoxItem Text="Item1" /> 
        <telerik:RadComboBoxItem Text="Item2" /> 
    </Items> 
</telerik:RadComboBox> 


client code:
 
    function OnClientSelectedIndexChanging(sender, args) { 
        if (args.get_item().get_text() == "Item2") { 
            if (!confirm('Do you want t continue...?')) { 
                args.set_cancel(true); 
            } 
        } 
    }  


Happy coding  :)
Shinu.
0
Justin Lee
Top achievements
Rank 1
answered on 25 Jun 2010, 02:30 PM
Ok. I see. I set it up the same way, but was using sender.get_value(), which was returning the old value.  args.get_item().get_value() returns the new item.

Thanks!
Tags
ComboBox
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Justin Lee
Top achievements
Rank 1
Share this question
or