This example demonstrates the flexible server-side validation mechanism of the Telerik RadGrid edit form.
There are three properties available under the ValidationSettings section of the control which can fine-tune the validation behavior of the grid edit form, namely:
- EnableValidation - boolean property specifying whether the data entered in the edit form will be validated server-side or not. The default value of this property is true and if the server validation fails the row will remain in edit mode.
- ValidationGroup - property of type string specifying to which validation group the buttons with CausesValidation = true from the edit form belong. This property is empty by default, however you can define outer validation group and fire the server code of its validators if needed. The edited item once again will retain its edit state - choose a validation group of your choice from the dropdown to see this in reality
- CommandsToValidate - array of strings designating on what type of command the edited row will be kept in edit regime if the server validation fails. The default items added to the array are PerformInsert and Update, however you can include your own command as well. Keep in mind that this property has a meaning only when EnableValidation is set to true
Furthermore, there is a custom validator attached to the Reorder level field which triggers server validation for the new entry. When the value in the textbox starts with '4', Page.IsValid will return false and the row will not be updated.
The same logic will work with ajax enabled for the grid with the limitation that the error messages for the outer validators will not be displayed. To do that you will need to disable the built-in AJAX for the grid and ajaxify the controls on the page through RadAjaxManager/RadAjaxPanel.
Instructions
To test the functionality on this example:
- Switch the edit modes using the Edit options menu at the top
- Enable/disable the validation for the grid using the checkbox from the Validation options menu
- Choose a validation group for the grid edit form controls by selecting an option from the dropdown list from the Validation options menu