Sharepoint multi-column validation

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:

ListEventReceiver

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";
           }
           base.ItemAdding(properties);
       }

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

CustomContenttype

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.

Answers


if you want to validation using ItemEventReceiver than you should use Sharepoint Error message page.

its will so you better of your Errormessage.I have used it.

Like :

  if (properties.AfterProperties["a1"].ToString() == properties.AfterProperties["a2"].ToString())
       {
           properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
           properties.RedirectUrl = properties.WebUrl + "/_layouts/error.aspx?ErrorText=Entry is Failure";
       }

or another way is Use PreSaveAction with javascript able to do valiation on list's forms.


Need Your Help

Customizing Drupal user account form

php drupal content-management-system

In my Drupal Site, i will be having two categories of users,say Category A and Category B. When a person wants to create an account on the site, i want to ask them which category they belong to and...