2012-06-11 37 views
1

我有一個包含多列的自定義列表。驗證由自定義內容類型進行。現在我想要兩列的組合是唯一的。直到我知道我沒有找到一種方法來解決這個問題,所以我的想法是使用eventreceiver或customcontenttype。Sharepoint多列驗證

我試了一下:

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); 
     } 

它工作正常,但錯誤信息未顯示爲驗證錯誤。這是一個新的錯誤頁面。 enter image description here

CustomContenttype

如果我嘗試在一個自定義的驗證CONTENTTYPE我不能從contentType中訪問其他字段的值。所以我無法比較兩個字段或檢查他們是獨特的。

回答

0

如果要驗證使用ItemEventReceiver比應該使用Sharepoint Error message page

它會讓你更好的ErrorMessage.I使用它。

像:

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

或另一種方式是使用PreSaveAction用JavaScript能夠做列表的形式valiation。

+0

謝謝,但我在尋找ValidationErrors,因爲這個錯誤會刪除表單中的所有內容,並且用戶必須重新輸入數據。 – HW90