Last post Dec 10, 2008 01:13 PM by ricka6
Dec 04, 2008 06:40 AM|JitendraShahani|LINK
I am new to Visual Studio and new to Dynamic Data. I have created this Dynamic site using Dynamic Data Web Site template. The language I have chosen is Visual Basic, also have chosen
LINQ To SQL classes & Northwind Database for this project.
I have written a validation that wants the Customer.CompanyName to start with ‘AMI’. Now even if the value starts with ‘AMI’, I get the validation error.
So to check what’s happening in the background I have set a MsgBox() to fire which returns me the field value.
Message box get’s fired twice, once with the updated value and then with the old value. So here’s the code I have written in customer class.
Kindly help me with your suggestions.
Public Property CompanyName()
Dec 04, 2008 07:38 AM|sjnaughton|LINK
I've tidied up the class:
Partial Public Class Customer
Private Sub OnCompanyNameChanging(ByVal value As String)
If Not value.StartsWith("AMI") Then
Throw New ValidationException("Company Name must start with AMI")
Public Class CustomerMetaData
Private _CompanyName As Object
<DisplayName("Company Name")> _
Public Property CompanyName() As Object
Set(ByVal value As Object)
_CompanyName = value
Hope this helps.
My thought is; and I've tested it and it does get called twice, should this happen and if so why?
The other way you could do what you want is via the OnValidate event in the DataContext and then throw your exception there, the only drawback there is that you will not get an error next to the field just in the summary [:(]
Dec 05, 2008 06:15 AM|JitendraShahani|LINK
Thanks very much for the help. I will certainly try out your solution and will come back with the result. Sorry for the code, showed properly in the preview.
Regards, Jitendra Shahani
Dec 05, 2008 04:50 PM|ricka6|LINK
Your partial class should not have Private _CompanyName
As Object or the get/set. That's why the method is being fired twice. The getter/setter is in the data model - you shouldn't duplicate it in your partial class.
How to: Customize Data Field Validation in the Data Model which has VB/C# samples.
Dec 10, 2008 05:57 AM|JitendraShahani|LINK
Dec 10, 2008 01:13 PM|ricka6|LINK
Can you get the VB sample at
http://msdn.microsoft.com/en-us/library/cc488527.aspx working. That should show you what you are doing wrong.