I've got a custom list that contains multi collumns. The validation is made by a custom contenttype. Now I want a combination of two columns to be unique. Until know I did not found a way to solve this problem with on-board functions, so my idea was to use the eventreceiver or a customcontenttype.

What I tried:


public override void ItemAdding(SPItemEventProperties properties)

           if (properties.AfterProperties["a1"].ToString() == properties.AfterProperties["a2"].ToString())
               properties.Status = SPEventReceiverStatus.CancelWithError;
               properties.Cancel = true;
               properties.ErrorMessage = "Failure";

It works fine, but the error message is not show as a validation error. It is a new errorpage. enter image description here


If I try to validate in a custom contenttype I can not access the value of an other field from the contenttype. So I can not compare two fields or check they are unique.

2 Answers 2


I think the only answer would be to look at doing this in Javascript on the client side.

I would also like to find a way to do this in server code and have it return a validation indication of an error, something like a "*" instead of a huge error page that cancels the entire entry.

Let me know if you have found your answer!


Could this be achieved by using a formula within the list validation settings?

Got to your List and select List Settings > Validation Settings. Use the below formula:


There is also an area for entering a user message for the validation error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.