Validation

There are 16 entries for the tag Validation
ValidationResult - Specifying Member Names

The System.ComponentModel.DataAnnotations.ValidationResult class was created for RIA Services, and it was introduced in Silverlight 3.0 and then added into .NET 4.0.  A ValidationResult represents a validation error condition, specifying the error message and, optionally, any member names that the error corresponds to.  If you use the [Required] attribute, the [Range] attribute, [StringLength], or any of the other provided ValidationAttribute classes, then ValidationResult instances are created to represent any validation failures.  If you have used the [CustomValidation] attribute or if you have derived from ValidationAttribute yourself, you have likely returned an instance of ValidationResult in your code, or ValidationResult.Success if validation...

posted @ Wednesday, February 24, 2010 11:42 PM | Feedback (1)

Validating Objects and Properties with Validator

ASP.NET Dynamic Data introduced the System.ComponentModel.DataAnnotations namespace in .NET 3.5 SP1.  The namespace contained a bunch of attributes for applying validation rules to objects and their properties.  With the “Alexandria” project (which morphed into .NET RIA Services plus some Silverlight/SDK/Toolkit additions), we were exposing your server-side entities up to your Silverlight client.  In doing this, we wanted to preserve your DataAnnotations attributes on the client, which of course meant that we needed a Silverlight version of this assembly. (See Also: Sharing Source with Silverlight). As our team was creating this Silverlight assembly, we found that we needed...

posted @ Friday, October 16, 2009 5:40 PM | Feedback (7)

Not Breaking on ValidationException (take 2)

Awhile back, I blogged about how Silverlight uses Validation Exceptions, which can cause the debugger to break.  I showed how to prevent that from happening, but the solution was less than ideal. Someone named rlodina commented on the post: What about manual adding: System.ComponentModel.DataAnnotation.ValidationException in this list. This comment has been sitting in my inbox for about a week, and I had wanted to follow up on this.  Well good gosh, this is easy and it works like a charm.  You can in...

posted @ Friday, August 07, 2009 7:44 PM | Feedback (5)

Async Validation with .NET RIA Services and DataForm

The Birth of QuickSilverlight.Validation Over on the .NET RIA Services forums, “SilverlightRIA” asked about performing asynchronous validation with .NET RIA Services and the Silverlight Toolkit’s DataForm.  He wanted to intercept the Commit from the DataForm and invoke his async validation, integrating the results into the DataForm’s validation UI.  This was an interesting scenario so I put some time into a solution for it this week.  The result is a library that I’m calling QuickSilverlight.Validation. Integrating Validation Results into DataForm It took a few hours of digging to find a way to get the async validation results to...

posted @ Saturday, July 11, 2009 5:05 AM | Feedback (8)

Validating Decimal Ranges with RangeAttribute

System.ComponentModel.DataAnnotations offers a RangeAttribute that can be used to validate that a value is within a given range.  Silverlight 3’s SDK includes this assembly and .NET RIA Services and ASP.NET Dynamic Data use this too. Something that a few of us have stumbled on here internally is that the RangeAttribute doesn’t have a constructor that takes Decimal values.  In fact, a bug was submitted by another feature crew for this.  Unfortunately, even if RangeAttribute offered a constructor that accepted decimals, you still wouldn’t be able to pass them in. Here’s what the code would look like: ...

posted @ Thursday, July 09, 2009 2:39 PM | Feedback (0)

Validation Exceptions in Silverlight

With the Silverlight 3 Beta SDK and .NET RIA Services, a lot of people are starting to utilize the System.ComponentModel.DataAnnotations library to add validation metadata to their entities.  Something that has tripped up some people is the use of exceptions for validation errors, where Visual Studio breaks with a user unhandled exception. As Keith Jones reported, Silverlight 3 uses exceptions to notify controls when validation has failed.  This means that many users will see Visual Studio break when these exceptions occur and be led to believe something has gone wrong.  But everything’s doing what it should.  If you hit...

posted @ Wednesday, April 01, 2009 10:33 AM | Feedback (4)

Custom Controls Everywhere Saves the Day

I just cannot advocate Custom Controls Everywhere strongly enough.  I find benefits for it all the time.  It saved the day again today.  Self-validating controls played into this one too. Here's what a co-worker reported to me a few minutes ago: Ron Ellis says (1:45 PM): on the textbox format = decimal Ron Ellis says (1:46 PM): if you enter just a "-" it bombs To which, I replied, "Lovely.  It sounds like our...

posted @ Thursday, March 13, 2008 2:11 PM | Feedback (1)

Self-Validating Form Controls

Ever since I started working with ASP.NET, back in v1.0 Beta 1, I've been creating self-validating form controls.  I've gone through a few iterations with them, but overall, the concept has stayed the same. Here's a fun link to an archive of the old Cincinnati .NET user group.  It shows where I gave a presentation back in February of 2003 on this topic.  I was trying to remember when that was, and archive.org was able to remember for me. On my current project, our Textbox got the most attention for validation.  We also...

posted @ Tuesday, February 12, 2008 10:16 PM | Feedback (2)

MVC and MVP Validation

I started a thread on Hanselforum regarding MVC and MVP validation.  Scott responded and I've added another post.  We're discussing where validation should be done in the MVC framework.  Here's what I wrote up as my latest post: It seems like the Model should "own" validation, but for usability, the View must be able to apply it. Ultimately, I think validation needs to be applied at the time of entry as well as at the time of persistence. I don't like self-servicing models (that can persist themselves), and I like being able to validate models in different...

posted @ Tuesday, January 29, 2008 9:32 AM | Feedback (0)

Extended MVP Pattern - Article Recap

Over the past few months, I posted several times about my extended MVP Pattern.  Since this was an ill-planned series of posts, I wanted to post a list of the articles involved. Scott Hanselman's post showing off the ASP.NET MVC framework triggered me to finally write about what I had created. Here's the list of my articles though: An Extended MVP Pattern (MVP Validation) MVC/MVP Validation - How's it done? MVC vs. MVP Criticism of my Extended MVP Pattern Response to Criticism...

posted @ Wednesday, January 23, 2008 10:42 PM | Feedback (0)

ASP.NET MVC - First Use

I've been using the ASP.NET MVC extensions tonight; this is the first time I've played with it.  My initial reaction is a bit mixed. The first thing that I got irritated by was that I cannot use any of the ASP.NET validator controls.  I was creating a login form with email address and password, and I wanted to require both of the fields.  With MVC, I can't just slap a validator on and call it a day; I actually have to write the validation logic myself.  Oh, and I can't just use a ValidationSummary control either--I have to render...

posted @ Thursday, January 17, 2008 2:32 AM | Feedback (2)

Extended MVP Pattern - Domain Validation

When I wrote my Extended MVP Pattern article back in November, it got some criticism.  Specifically: Each 'thing' in the model should include it's own business rules, validation rules, security, and persistance [sic] rules. I argued that I've seen times with having all of the validation (and all other logic) in the domain layer doesn't pan out.  However, what I didn't talk about in detail was that my extended MVP pattern actually satisfies the desire to put the validation logic into the domain layer. When I started creating my pattern, having the validation...

posted @ Tuesday, January 15, 2008 1:20 AM | Feedback (16)

Response to Criticism of my Extended MVP Pattern

As I posted, I received some criticism about my extended MVP pattern over on ScottGu's blog.  I wanted to submit my response here, and I'll link to this post in a comment on ScottGu's blog. I will venture to guess that the vast majority of the folks that read ScottGu's blog are pretty sharp folks.  And experienced software developers know that there is no sure-fire solution to every problem; there is no single architecture or design pattern that fits every project; there is no silver bullet so to speak.  Microsoft's offering of an MVC framework as well as a...

posted @ Monday, November 19, 2007 10:02 PM | Feedback (3)

Criticism of my Extended MVP Pattern

Over on the ASP.NET MVC (Part 1) thread on ScottGu's blog, there's a little discussion between myself and a couple of others about whether or not a controller should have any logic in it. Doug Ramirez stated: Each 'thing' in the model should include it's own business rules, validation rules, security, and persistance [sic] rules. Doug was stating that Microsoft should publish best practices and guidelines for how to build MVC applications, and he was dictating that controllers should not have any logic--all logic should be housed within your business objects. I...

posted @ Monday, November 19, 2007 5:50 PM | Feedback (0)

MVC/MVP Validation - How's it done?

ScottGu posted Part 1 of a series about ASP.NET MVC.  One of the comments asked, "How is input validation going to work?"  That's something that I've been wondering about as well.  With the ASP.NET MVC framework, and others it seems, if the controller has no reference to the view, how does the controller tell the view that the first name field is required?  How does the controller tell the view that the phone number field must be a valid US phone number?  Moreover, how does the controller enforce field-level security, or anything else that would require fine-grained control over the...

posted @ Tuesday, November 13, 2007 12:25 PM | Feedback (0)

An Extended MVP Pattern (MVP Validation)

Until last year, I had never used an MVP/MVC pattern before.  I had read about the patterns at Martin Fowler's site, although the Model View Presenter pattern has since been retired.  I had also seen some posts and demos and talks where people were using MVC/MVP frameworks.  But I kept thinking there was something missing.  I couldn't put my finger on it for a long time, but I just had that gut feeling that something wasn't covered. Last year though, I was assigned to a new project, for the first time in a few years.  The new project was...

posted @ Friday, November 09, 2007 3:43 AM | Feedback (1)