In the context_SavingChanges method of my partial metadata class I am doing custom validations which throw a ValidationException.
Now it occurs to me that when this validationException is thrown it resets all the form fields.
When I however use for example the Required attribute on a field and I do not fill it on on purpose it will show the errorMessage that I gave the attribute, but it does not clear the form fields.
Please make sure that you've used javascript or something related to that to validate your field values instead of on the server-side to avoid the problem of "whole page" refreshing and causes this problem.
Hi Yannick, I'm sure the reason they get reset when you throw a validation exception in the data model is because the page gets a full refresh. But the reason the do not get reset with the required field and any of the other standard validators is because
the validation is being run on the client.
There may be a way to pass the entity values back to the page in the exception somehow, but I'm not sure.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Yannick86
Member
565 Points
366 Posts
Custom Validation clears form fields
Nov 05, 2012 08:15 AM|LINK
Hey all,
In the context_SavingChanges method of my partial metadata class I am doing custom validations which throw a ValidationException.
Now it occurs to me that when this validationException is thrown it resets all the form fields.
When I however use for example the Required attribute on a field and I do not fill it on on purpose it will show the errorMessage that I gave the attribute, but it does not clear the form fields.
Anyone got an idea?
Thanks in advance,
- Yannick
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Custom Validation clears form fields
Nov 06, 2012 12:17 AM|LINK
Please make sure that you've used javascript or something related to that to validate your field values instead of on the server-side to avoid the problem of "whole page" refreshing and causes this problem.
If necessary, please show us your codes.
Reguards!
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Custom Validation clears form fields
Nov 06, 2012 09:58 AM|LINK
Hi Yannick, I'm sure the reason they get reset when you throw a validation exception in the data model is because the page gets a full refresh. But the reason the do not get reset with the required field and any of the other standard validators is because the validation is being run on the client.
There may be a way to pass the entity values back to the page in the exception somehow, but I'm not sure.
Always seeking an elegant solution.
Yannick86
Member
565 Points
366 Posts
Re: Custom Validation clears form fields
Nov 08, 2012 01:13 PM|LINK
Hey Steve,
Good to see you're still on this forum :)
Do you have any sample on how this is normally done?
Kind regards and thanks in advance,
- Yannick
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Custom Validation clears form fields
Nov 08, 2012 10:06 PM|LINK
Hi Yannick, I'm thinking :)
Always seeking an elegant solution.
Yannick86
Member
565 Points
366 Posts
Re: Custom Validation clears form fields
Nov 22, 2012 08:22 AM|LINK
Hey Steven, still thinking? ;P :D
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Custom Validation clears form fields
Nov 22, 2012 09:41 AM|LINK
I still can't think of a way of doing this sorry.
Always seeking an elegant solution.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Custom Validation clears form fields
Nov 23, 2012 12:32 AM|LINK
Hi again,
It's not so easy to do with that, just like what the MVP said. I still suggest you using jQuery or javascript to deal with that.
Or just use attributes applied on the public properties, or write your own methods to be instead of partial methods.