I'm trying to override the On_Updating event of one of my Dynamic Data fields and throw an exception under certain circumstances. For example:
<MetadataType(GetType(Section4_Metadata))> _
Partial Public Class Section4
Private Sub OnContact_EmailChanging(ByVal value As String)
If Not [Char].IsUpper(value(0)) Then
Throw New ValidationException( _
"Email must start with an uppercase letter.")
End If
End Sub
End Class
While this works to catch the scenario, it just throws an unhandled exception, so I get an error page.
But according to the MSDN documentation,
"Any validation exceptions that are thrown in the data model are caught by the DynamicValidator control.
If a page contains a DynamicValidator control, the error can be displayed in the page."
So this is in my Edit.aspx, which has a DynamicValidator control. Are they wrong?
Not gonna lie, I don't think I'd know where to start. I haven't found the plain-jane DynamicValidator hiding within the DynamicData folder, so I'm assuming it's a control in a library somewhere, but beyond that...
xaeryan
Member
97 Points
288 Posts
DynamicValidator not catching my thrown exception
Sep 29, 2009 08:24 PM|LINK
I'm trying to override the On_Updating event of one of my Dynamic Data fields and throw an exception under certain circumstances. For example:
<MetadataType(GetType(Section4_Metadata))> _ Partial Public Class Section4 Private Sub OnContact_EmailChanging(ByVal value As String) If Not [Char].IsUpper(value(0)) Then Throw New ValidationException( _ "Email must start with an uppercase letter.") End If End Sub End ClassWhile this works to catch the scenario, it just throws an unhandled exception, so I get an error page.
But according to the MSDN documentation,
"Any validation exceptions that are thrown in the data model are caught by the DynamicValidator control. If a page contains a DynamicValidator control, the error can be displayed in the page."
So this is in my Edit.aspx, which has a DynamicValidator control. Are they wrong?
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: DynamicValidator not catching my thrown exception
Sep 30, 2009 12:23 PM|LINK
I think that this has been seen before and there was a fix for this as the error was being wrapped in some other exception see the ImprovedDynamicValidator.cs in the Dynamic Data Futures project here http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=14475
Dynamic Data
Always seeking an elegant solution.
xaeryan
Member
97 Points
288 Posts
Re: DynamicValidator not catching my thrown exception
Sep 30, 2009 12:33 PM|LINK
Shucks, I guess they haven't put this in DD4, as I'm using .NET 4 for this project.
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: DynamicValidator not catching my thrown exception
Sep 30, 2009 01:33 PM|LINK
You may be able to use this in DD v4 if you look how they wired it up in the old Futures project.
Dynamic Data
Always seeking an elegant solution.
xaeryan
Member
97 Points
288 Posts
Re: DynamicValidator not catching my thrown exception
Sep 30, 2009 01:50 PM|LINK
Not gonna lie, I don't think I'd know where to start. I haven't found the plain-jane DynamicValidator hiding within the DynamicData folder, so I'm assuming it's a control in a library somewhere, but beyond that...
DaveRuss
Participant
801 Points
172 Posts
Re: DynamicValidator not catching my thrown exception
Sep 30, 2009 03:05 PM|LINK
This article may be a good place to start.
Not quite the same reason, but it also requires the DynamicValidator to be enhanced so it might help.
Dave
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: DynamicValidator not catching my thrown exception
Oct 01, 2009 08:50 AM|LINK
The DynamicDataValidator is in the old Futures project inside the Controls folder.
Dynamic Data
Always seeking an elegant solution.
BrianPritcha...
Member
82 Points
42 Posts
Re: DynamicValidator not catching my thrown exception
Oct 10, 2009 04:42 PM|LINK
Will the DynamicValidator be fixed in the next DD release so we don't have to keep using the ImprovedDynamicValidator?
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: DynamicValidator not catching my thrown exception
Oct 10, 2009 06:31 PM|LINK
Good Question [:D] and did that get you the ImprovedDynamicValidator?
Dynamic Data
Always seeking an elegant solution.