Telerik RadListBox onClientTransferred not firing with disabled items selected and transferred, workaround

Telerik RadListBox onClientTransferred not firing with disabled items selected and transferred, workaround

Was running into an issue when selecting disabled items with a telerik radListBox.

Normally you would not be able to select disabled items with the radListBox, but there is a known bug that allows you to do so by holding shift and selecting disabled items along with enabled items. This is documented here http://www.telerik.com/community/forums/aspnet-ajax/listbox/able-to-select-disabled-items.aspx.

The specific issue was that by selecting disabled items, and transferring them to a new listbox, the onClientTransferred event for the grid was not firing. This same issue is brought up by someone here: http://www.telerik.com/community/forums/aspnet-ajax/listbox/disabling-item-in-radlistbox—onclienttransferred-not-firing-correctly.aspx

We needed to take advantage of this onClientTransferred event to run a javascript function that was responsible for synching a dropdown list with our radListBox via clientside code. We needed it to run anytime a transfer was completed, and so these 2 issues above were causing us some problems.

There was no solution presented, but with the help of a coworker we came up with something ourselves, solution to follow:

The javascript function we wanted called on the onClientTransferred was updateOrderbyDropDown(), the contents of the function are not really relevant to this post, but simply that it needs to be called after ever client transfer on this grid.

My coworker instructed me that we could wrap the radListBox Javascript function we wanted called, so that it was called after every transfer on this radListBox.  We needed to find a function that we could use and after some investigation we discovered there was a function called Transfer, with 6 parameters, that was called by the radListBox after every transfer. We discovered this Transfer function with the help of firebug and its script panel. We decided that this function would fit our needs.

The first thing we needed to do was to wrap the Transfer(n,j,o,l,p,g) function we wanted. This was accomplished by calling our pageLoad() function (shown below) in either document load or ready.  We created a function called overrideListboxTransferFunction(n,j,o,l,p,g) that used the exact same signature as the Transfer(n,j,o,l,p,g) function we wanted to wrap. The function looks like this:

function pageLoad() {

    var toListBox = $find(selectedColumnListBoxClientID);
    var fromListBox = $find(availableColumnListBoxClientID);

    //proxy the onItemSelected methods of both lisboxes, so we can apply custom logic to the transfer buttons
    fromListBox._transfer = wrap(fromListBox._transfer, null, overrideListboxTransferFunction, fromListBox);
}

The wrap function we used, is referenced from a stack overflow article here:
http://stackoverflow.com/questions/5258829/wrapping-a-function-in-javascript-jqueryand it looks like this:

var wrap = function (functionToWrap, before, after, thisObject) {
    return function () {
        var args = Array.prototype.slice.call(arguments),
            result;
        if (before) before.apply(thisObject || this, args);
        result = functionToWrap.apply(thisObject || this, args);
        if (after) after.apply(thisObject || this, args);
        return result;
    };
};

Now we just need to implement “our version of the transfer function. As you can see from abovewe called it overrideListboxTransferFunction(n, j, o, l, p, g) with 6 parameters. It isimportant that the number of parameters match the underlying telerik javascript functions signature like so:

function overrideListboxTransferFunction(n, j, o, l, p, g) {
    updateOrderbyDropDown();
}

So by wrapping this transfer function, so that our “customized version of it is called after
every single call to the original. We were able to solve our issue. updateOrderbyDropDown() is now able to be called on every
transfer. Regardless of if onClientTransferred is called or not.

 

 

There are 2 comments .

Glenn —

Wow! This works beautifully! …This was the only way to fix a similar problem with needing a 100% reliable method to handle post Transfer events. Thanks for sharing!!

Reply »
    brent

    Glad it helped you Glenn! I like to post those annoying quirks I find with Telerik since I know other developers might be pulling their hair out on the same problems.

    Reply »

Share Your Thoughts!

Testimonials

What My Clients Say

Karin - Hope and Future

Brent has always been very prompt and generally exceeds our expectations with his work. His maintenance fee is very reasonable. I strongly recommend him!  We get many compliments on our beautiful web site!

Dan

I contacted Krueger Web Design and Brent did everything.  He setup a test site with the changes so we could verify everything was correct before we transferred from my old hosting provider.  During the setup and conversion Brent was extremely professional and responsive. He responded to any issues the same day.

Dan Kaufman
Emily - GFCLT

We've had a great experience working with Krueger Web Design. Prompt responses, great ideas, effective work... all at a reasonable price! This was the perfect fit for our organization.

Mahmud - ACMC

I would love to recommend you to anyone! You have been very helpful when we needed you the most.

Brian - SEMNIC

Working with Krueger Web Design was effortless. Communicating what I wanted for the website and the results that I saw were identical. The customer service was always prompt and I am completely satisfied with the product.

Zach - Stadium Club

Exactly what I wanted! Fast turnaround time and very affordable. Answered all of our questions quickly and made adjustments promptly. Very easy to work with and puts everything into terminology that even I can understand!

Contact Krueger Web Design

Have a question for me? Need an estimate on some work? You can email me at brent@kruegerwebdesign.com or drop me a line using the button below:

Copyright © 2017 Krueger Web Design - All rights reserved
Web Design in Madison, WI