partial void OnValidate(System.Data.Linq.ChangeAction action)
{
if (action == ChangeAction.Delete)
{
MyDataContext dc = new MyDataContext();
int amount = (from l in dc.Links
where l.Parent == this.Id
select l).Count();
if (amount > 0)
throw new ValidationException("Unable to delete a parent object, delete the children first");
}
}
The exception is displayed in the regular yellow screen !
I would try the OnValidate in a new scaffolded project to see if it's something in your current project. I done as you have an it appears in the ValidationSummary as it should.
Also Make sure you are running Dynamic Data that comes with VS2008 SP1. if your project is originally from an earlier release then I would start a new.
Dynamic DataBusiness LogicOnValidate
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
None
0 Points
11 Posts
ValidationSummary doesn't display exception !
Nov 19, 2008 09:57 AM|itay.basoni|LINK
Hi,
I have the following code:
The exception is displayed in the regular yellow screen !
Any ideas ?
All-Star
39486 Points
8916 Posts
Re: ValidationSummary doesn't display exception !
Nov 19, 2008 10:26 AM|rtpHarry|LINK
Here is one approach to displaying the exceptions:
Here is a better one:
None
0 Points
11 Posts
Re: ValidationSummary doesn't display exception !
Nov 19, 2008 11:20 AM|itay.basoni|LINK
No dude,
In Dynamic-Data projects exceptions are being displayed automatically in the validation summary control, atleast should be displayed automatically.
Right now i get them in a javascript alert box and when I set the EnablePartialRendering to false it displays the .net yellow error page =/
Does anyone know whether I should set something in the configuration to enable this type of behavior ?
All-Star
17916 Points
5681 Posts
MVP
Re: ValidationSummary doesn't display exception !
Nov 19, 2008 12:16 PM|sjnaughton|LINK
I would try the OnValidate in a new scaffolded project to see if it's something in your current project. I done as you have an it appears in the ValidationSummary as it should.
Also Make sure you are running Dynamic Data that comes with VS2008 SP1. if your project is originally from an earlier release then I would start a new.
Dynamic Data Business Logic OnValidate
Always seeking an elegant solution.
None
0 Points
11 Posts
Re: ValidationSummary doesn't display exception !
Nov 19, 2008 01:56 PM|itay.basoni|LINK
I did all of that and still nothing .. I even removed the MVC preview i had installed just to be certain.
I'll try to reinstall the framework and perhaps also the V.S during this weekend ... it must be a problem with the references.
The funny thing is - it worked on the preview version !
Thanks anyway, I appreciate your help.
Contributor
3384 Points
1363 Posts
Re: ValidationSummary doesn't display exception !
Nov 19, 2008 05:15 PM|davidebb|LINK
We actually saw this issue before, or something similar. Could you try making the following change in the page template:
<asp:LinkButton ID="DeleteLinkButton" runat="server" CommandName="Delete"
CausesValidation="true" Text="Delete"
OnClientClick='return confirm("Are you sure you want to delete this item?");' />
See this thread for reference.
thanks,
David
None
0 Points
11 Posts
Re: ValidationSummary doesn't display exception !
Nov 22, 2008 02:36 PM|itay.basoni|LINK
Thank you, it's finally working :)
The code I've written handles the SQLException - "DELETE failed because of FOREIGN KEY constraint".
I think, and I'm sure you'd agree, this exception should be automatically handled by Linq or DynamicData.
Thanks again for the great help you've given.
Star
12522 Points
2214 Posts
Microsoft
Re: ValidationSummary doesn't display exception !
Nov 22, 2008 11:14 PM|ricka6|LINK
Yes we agree. It will be fixed in the next version.
None
0 Points
2 Posts
Re: ValidationSummary doesn't display exception !
Dec 08, 2010 07:29 AM|subong|LINK
I Have the same problem with ListDetails.aspx. (vs2008 sp1, asp.net3.5 sp1)
Is it posible to set CausesValidation property?.
thanks.
Dyanamic Data Web Site
All-Star
17916 Points
5681 Posts
MVP
Re: ValidationSummary doesn't display exception !
Dec 08, 2010 08:27 AM|sjnaughton|LINK
Hi subong, yes it is but you will have to add the relavent button to the GridView like in the List page.
Dynamic Data 4
Always seeking an elegant solution.
None
0 Points
2 Posts
Re: ValidationSummary doesn't display exception !
Dec 08, 2010 11:23 AM|subong|LINK
ASP.NET Dynamic Data