Confirm popup on selected index change

3 posts, 1 answers
  1. Justin Lee
    Justin Lee avatar
    170 posts
    Member since:
    Dec 2009

    Posted 24 Jun 2010 Link to this post


    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. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jun 2010 Link to this post

    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.
  3. Justin Lee
    Justin Lee avatar
    170 posts
    Member since:
    Dec 2009

    Posted 25 Jun 2010 Link to this post

    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!
Back to Top