ASP .NET AJAX Control Toolkit Reorder List control and LINQ
The ASP .NET AJAX Toolkit is quite a useful and yet under-used set of controls. However they can also quickly lead to bizarre issues and worse performance than normal if they are not properly understood or used correctly. This issue is compounded when you take into consideration that quite a few of the controls included have a number of fairly unique bugs in them.
An instance of this is in the Reorder List control which is intended to allow a user to re-order a list of items by simple dragging and dropping them, instantly altering the database when they do it. While the control works, it appears to have some pretty strange behaviour in how it updates its list when a user drags and drops an item into a new position.
Put simply, it requires the update method signature to contain all the properties it is aware of on the list of objects you databind it to. This had me stumped for quite a while when I was investigating why this control was not working as expected.
Eg. You have an class called generated by LINQ to SQL Person and this class has the properties FirstName, LastName and Age. You then set a List of people as the Reorder list’s DataSource, everything works as expected. Great!
However unless your Update method’s signature contains your object’s Id, FirstName, LastName and Age the Reorder List will fail to commit the changes to the database and you will find your re-ordering mysteriously disappears when the page is reloaded.
To resolve this, simply change your method’s signature to include the missing object properties as relevant and everything will work as expected. The additional parameters do not need to be used in the method they just need to be there in order for the control to work as expected.
I hope this helps someone out since it kept me entertained for hours during the development of a project and didn’t seem to be too well documented online with regards to using LINQ to SQL with this control.