data annotations - Server/Client input validation for asp.net form using attribute / dataannotation -


I was playing with data validation verification of asp.net mvc 2. This client is very well connected to the side verification. I really like that I can only define a set of rules and enable it to be used on both the client and server side parties.

I wonder if it is possible to do this with ASP.NET form. The following code snippet shows how this is done, and simple data validation on the server side works fine when the object is created.

However, I would like to reuse the verification check on the client side or do not need to define 2 sets of validation definition on client / breaking the ASP.NET JavaScript library). [Required (ErrorMessage = "property is required.")] [Regular expansion ("" ^ [0-9] * (\.)? [0-9] + $ [Datamember, display name] ", Error message =" property format invalid ")] get public string property {}; Set; }

and I have created the following method on the base class to verify

  public bool IsValid () {bool result = true; PropertyInfo [] attribute = this. Gettype () GetProperties (); Foreach (Property Info Asset in Properties) {// Receive all custom validation attributes var cusAttributes = property.GetCustomAttributes (typeof (validation attribute, right)). OFTIP & lt; Validation attribute & gt; (); Fortech (Variable attribute in Cos Attributes) {// Validate different attribution base on this custom attribute. Boolean isValid = attribute.IsValid (property.GetValue (this, blank)); // If the attribute is not valid, then log in to the error message archive (! IsValid) {this.ErrorMessages.Add (new errorSummary () {ErrorMessage = attribute.ErrorMessage}); Result = false; }}} Return result; }  


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -