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

SelectedIndexChanging old value

4 Answers 183 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
eakins05
Top achievements
Rank 1
eakins05 asked on 15 Dec 2009, 10:29 PM
Is there a way to get the old value out of the ListBox on SelectedIndexChanging event?  I'm converting a ComboBox over to a ListBox and I was previously doing something very similar to this: http://www.telerik.com/help/aspnet-ajax/combo_clientsideonclientselectedindexchanging.html.  But now my sender.get_selectedItem() returns null.  On inspection, sender._selectedValue seems to hold the previous selected value.  I can easily keep track of my previously selected item on my own, but if there's a cleaner way to do it (like before), I'm all ears.

Thanks,
Jared

4 Answers, 1 is accepted

Sort by
0
eakins05
Top achievements
Rank 1
answered on 15 Dec 2009, 10:49 PM
Here's my current workaround:

    var ignoreCheck = false
    var changingItem; 
    function RadListBox2_ClientSelectedIndexChanging(sender, args) 
    { 
        if (ignoreCheck) 
        { 
            ignoreCheck = false
            return
        } 
        var currentItem = changingItem; //sender.get_selectedItem(); (from before) 
        changingItem = args.get_item(); 
        if (currentItem) { 
            args.set_cancel(true); 
            PageMethods.DoCheck(currentItem.get_value(), DoCheck_Success); 
        } 
    } 
 
    function DoCheck_Success(result) 
    { 
        if (!changingItem) return
         
        if (result || confirm('Do you want to continue (changes will be lost)?')) 
        { 
            ignoreCheck = true
            changingItem.select(); 
        } 
    } 
 

Now my args.set_cancel(true) doesn't seem to be having any effect at stopping the selection change; it's posting back before my PageMethod handler has a chance to do the confirm.  Can you help out?


0
Genady Sergeev
Telerik team
answered on 18 Dec 2009, 11:37 AM
Hi eakins05,

After some investigation it turned out that this is bug in the RadListBox. We will try to have it fixed for the next week. Until then, I suggest that you use the workaround that you have found. I have updated your telerik points for pointing us to this issue.

Sincerely yours,
Genady Sergeev
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.
0
eakins05
Top achievements
Rank 1
answered on 18 Dec 2009, 05:25 PM
Thanks for the reply and for looking into this.  For anybody interested in this immediately, here's my workaround for the args.set_cancel(true) not working:

Use this method for OnClientSelectedIndexChanged
function RadListBox2_ClientSelectedIndexChanged(sender, args) { 
    __doPostBack('<%=RadListBox2.ClientID.Replace("_", "$") %>'''); 
and set AutoPostBack="false" in the markup.

The set_cancel was cancelling the event (it wouldn't hit the clientside SelectedIndexChanged), but it wasn't cancelling the postback (it would postback regardless of the cancel request).  This workaround will still hit your serverside OnSelectedIndexChanged handler.



0
Genady Sergeev
Telerik team
answered on 21 Dec 2009, 05:41 PM
Hi eakins05,

We have already fixed the bug as you can check on the latest internal build. Information on how to obtain the latest internal can be found here.

Sincerely yours,
Genady Sergeev
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
eakins05
Top achievements
Rank 1
Answers by
eakins05
Top achievements
Rank 1
Genady Sergeev
Telerik team
Share this question
or