locked
Client side validation using Client OM in sharepoint 2010 RRS feed

  • Question

  • Hi,

    Can we use Client Object Model for Client side validation?

    Suppose, i have a SharePoint 2010 List. While adding a new item in that list, i want to check for Title is already available or not, person has posted any item earlier or not..that kind of stuff. Could i check this at client side rather than ItemAdding Event, so that i can reduce the network traffic?

    Thanks in advanced.

    Hardik Shah

    Solution Developer.

    Friday, September 10, 2010 6:41 AM

Answers

  • Yes i suppose you could, but doubt if it would be faster then a ItemAdding event, because at some point you have to fire a query that retrieves all list items and some properties, so you can check them. And the Query you will fire with the OM might be a bit slower depending on how much properties you would need.

    I made a blogpost about publishing your items; http://blogs.tamtam.nl/appie/2010/08/17/Batch+Publish+With+The+Ribbon.aspx and a colleague made a similair blogpost http://blog.petergerritsen.nl/2010/09/06/ribbon-buttons-and-the-client-object-model/ you can use both posts to retrieve a set of SPListItems and thus their propperties so  you can check them.

    • Marked as answer by Wayne Fan Friday, September 24, 2010 3:39 AM
    Friday, September 10, 2010 7:35 AM
  • I agree with Appie203 that it would not be feasible with large lists. However, you can apply a unique constraint to a sharepoint field. The out of the box Title field does not allow this, however, you could create your own and apply the constraint when creating the field in the UI. This lets SharePoint handle the logic and you would not need to loop through all the items on the client or handle it in the ItemAdding event.
    certdev.com
    • Marked as answer by Wayne Fan Friday, September 24, 2010 3:39 AM
    Friday, September 10, 2010 1:57 PM

All replies

  • Yes i suppose you could, but doubt if it would be faster then a ItemAdding event, because at some point you have to fire a query that retrieves all list items and some properties, so you can check them. And the Query you will fire with the OM might be a bit slower depending on how much properties you would need.

    I made a blogpost about publishing your items; http://blogs.tamtam.nl/appie/2010/08/17/Batch+Publish+With+The+Ribbon.aspx and a colleague made a similair blogpost http://blog.petergerritsen.nl/2010/09/06/ribbon-buttons-and-the-client-object-model/ you can use both posts to retrieve a set of SPListItems and thus their propperties so  you can check them.

    • Marked as answer by Wayne Fan Friday, September 24, 2010 3:39 AM
    Friday, September 10, 2010 7:35 AM
  • I agree with Appie203 that it would not be feasible with large lists. However, you can apply a unique constraint to a sharepoint field. The out of the box Title field does not allow this, however, you could create your own and apply the constraint when creating the field in the UI. This lets SharePoint handle the logic and you would not need to loop through all the items on the client or handle it in the ItemAdding event.
    certdev.com
    • Marked as answer by Wayne Fan Friday, September 24, 2010 3:39 AM
    Friday, September 10, 2010 1:57 PM