Last post Oct 20, 2010 06:20 AM by sjnaughton
Oct 10, 2010 03:08 PM|maan1978|LINK
doing validation using attributes or onpropertychanging will show nice error next to the control
but when Iam using onvalidate how can I set error message next to the controls that caused the logic error ?
partial void OnValidate()
//throw new ValidationException("Error ");
I want to set the error message next to the Orderdate , and RequiredDate controls( Northwind database).
Oct 10, 2010 08:57 PM|eatingmashin|LINK
Why not use <asp:CompareValidator ? :D
Oct 11, 2010 06:29 AM|pranav rastogi|LINK
OnValidate() exceptions are thrown at the entity level and thus show up in the validation summary.
If you want error messages to be reported at the column level then you should have your logic in the OnPropertyChanging event itself
Oct 11, 2010 08:21 AM|maan1978|LINK
I posted the code as a sample for some cases where I want to do bussiness logic at the OnValidation
I have more complicated scenarios than compare.
Dear pranav rastogi,
I can not do all the logic using the onpropertychanging
I have many cases where the property is not changing .
I used different kind of ORM , for example dataset ,and I usually do row.error="Error string".
dynamic data Validation linq to sql
Oct 12, 2010 10:38 PM|pranav rastogi|LINK
The validation summary will have the error message that you would throw from your OnValidate() so what is the specific scenario here that you want to show the error message next to the row/column
Oct 12, 2010 11:46 PM|maan1978|LINK
message at the summary , star next to the control.
Oct 14, 2010 07:51 AM|maan1978|LINK
Is there any solution for my question ???
Oct 14, 2010 07:37 PM|sjnaughton|LINK
Hi Mann1978, when you use the OnValidate of any entity level validation there is no way to let the system know which field to show the error against, you would need to do some custom validation at field level. I usually create custom field template for this
sort of thing.
Oct 20, 2010 12:30 AM|maan1978|LINK
Can I get a sample ?
Oct 20, 2010 06:20 AM|sjnaughton|LINK
Hi Maan1978, all I do is make a copy of the FieldTemplate that the field currently uses for Edit say Text_Edit.ascx (in the /DynamicData/FieldTemplates folder) the I add a CustomValidation control to the markup and wireup it's OnServerValidate or set ClientValidationFunction
Custom Field Templates
Dynamic Data 4