Hi, I've a grid:
<telerik:RadGrid ID="Grid" runat="server" GridLines="None" AllowPaging="True" CssClass="RadGrid" AllowSorting="True" AutoGenerateColumns="false" ShowStatusBar="true" AllowFilteringByColumn="true"> <ValidationSettings EnableValidation="true" EnableModelValidation="true" CommandsToValidate="Insert,Edit,Update" /> <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="Id" InsertItemPageIndexAction="ShowItemOnCurrentPage">And I am using EF as Datasource (with RepositoryPattern).
Furthermore I user Dataannotations - so every Entity has a partial MetadataClass with Annotations like:
[MetadataType(typeof(entityMetadata))] public partial class entity { internal sealed class entityMetadata { [Required(ErrorMessage="Id is required")] public Int32 Id { get; set; } [Required(ErrorMessage="Name is required")] [StringLength(400)] public String Name { get; set; } [Required(ErrorMessage="Description is required")] public String Description { get; set; } } }I thought with "EnableModelValidation" the Grid would automatically validate against this annotations.
But it doesn't.
My UpdateCommand looks like this:
void Grid_UpdateCommand(object sender, GridCommandEventArgs e)
{
using (IGenericRepository<Lov_KpiType> repositroy = new GenericRepository<Lov_KpiType>())
{
GridEditableItem item = e.Item as GridEditableItem;
int kpiType_Id = Convert.ToInt32(item.GetDataKeyValue("Id").ToString());
Lov_KpiType kpiType = repositroy.FindById(kpiType_Id);
item.UpdateValues(kpiType);
repositroy.SaveChanges(); }
}
The item is not updated and the Grid changes to TemplateMode again. No errormessage is show at this time..
I thought, as it is in MVC, when Data-Annotations are used - no Postback is done when ClientSideValidation fails.
Furthermore I do not know, how to determine if there is an validation-error in code behind.
Please help :)

<telerik:GridNumericColumn DataField="AMT1" UniqueName="AMT1 HeaderText="Amount1"
DataType="System.Int32" DataFormatString="{0:N0}" DecimalDigits="0"
ForceExtractValue="Always" SortExpression="AMT1" AllowFiltering="false" EmptyDataText="0"
Aggregate="Sum" FooterAggregateFormatString="{0:c0}" FooterStyle-HorizontalAlign="Right" >
<ItemStyle HorizontalAlign="Right" />
</telerik:GridNumericColumn>
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" MasterPageFile="~/MainMaster.master" Title="FittleBug Demo" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server" ID="Content1"> <script type="text/javascript" src="js/fancybox/jquery.fancybox-1.3.4.pack.js"></script> <link href="js/fancybox/jquery.fancybox-1.3.4.css" rel="stylesheet" type="text/css" /> <asp:Literal ID="clientScript" Mode="PassThrough" runat="server" /> Site Content <!-- Steps --> <div style="display:none"> <div id="HomeStep1" style="color:#3F3C2D; margin:10px 0 15px 0;padding:0 0 0 10px;width:450px;height:250px;"> <div><asp:Literal id="SiteWelcome" runat="server"/></div> <div style="font-size:16px; padding:10px 0 3px 0;">Please Enter Your Zip Code</div> <div style="vertical-align:top;height:45px;"> <div id="zipWrapper"> <telerik:RadMaskedTextBox id="txtZipcode" RequireCompleteText="true" PromptChar=" " ResetCaretOnFocus="true" SelectionOnFocus="CaretToBeginning" AutoCompleteType="HomeZipCode" CssClass="required digits zipcode" runat="server" /> </div> <input type="button" id="btnGo" value="GO > " /> <br style="clear:both;" /> <span id="valZipcode" style="display:none">Please enter a valid zip code</span><span id="unknownZipcode" style="display:none">Sorry, we do not provide services in that zipcode</span> </div> </div> </div> <div style="display: none"> <asp:HiddenField ID="rdNumerticTextBox" runat="server" /> <asp:ImageButton ImageUrl="~/images/btn-go.png" runat="server" ID="imgbtnGo" OnClick="imgbtnGo_ShowData" /> </div><script type="text/javascript"> jQuery(function ($) { var $hidden = $("#" + aspHiddenId); var $button = $("#" + aspButtonId); var $zipcode = $("#<%=txtZipcode.ClientID %>"); var $zipPopup = $("#zipPopup"); var $btnGo = $("#btnGo"); var $valZipcode = $("#valZipcode"); var $unknownZipcode = $("#unknownZipcode"); $('a[href*="youtube.com"]').fancybox({ 'type': 'iframe' }); $zipcode.val($hidden.val()); $zipPopup.fancybox({ modal: true }) if ($zipcode.val() == "") { $zipPopup.click(); $zipcode.focus(); } $zipcode.keypress(function (e) { if (e.which === 13) { $btnGo.click(); } }); $btnGo.click(function () { var zipcode = $zipcode.val(); if (/^\d{5}$/.test(zipcode)) { $.ajax({ type: "POST", url: "services/ajax.svc/IsKnownZipcode", contentType: "application/json; charset=utf-8", data: $.toJSON({ "zipcode": zipcode }), dataType: "json", success: function (data) { if (data.d) { $valZipcode.hide(); $unknownZipcode.hide(); $hidden.val(zipcode); $.fancybox.close(); $button.click(); } else { $valZipcode.hide(); $unknownZipcode.show(); } }, error: function (msg) { alert("Error checking zipcode. Please try again."); } }); } else { $valZipcode.show(); $unknownZipcode.hide(); } return false; }); });</script></asp:Content>