Client side Validation using CSLA

Client side Validation using CSLA

Old forum URL: forums.lhotka.net/forums/t/8425.aspx


bharat0204 posted on Thursday, January 28, 2010

Hi,
i am new to CSLA framework and in my project it is used.so can i use client side validation using CSLA rather than going to server for simple textbox empty or require field validation.
if yes then please let me know how to achieve that.
as in my current project for checking type or length it is implemented in class for e.g

ValidationRules.AddRule(CommonRules.StringRequired, "ContributionName");

which simply done by requirefieldvalidator control

and

ValidationRules.AddRule(CommonRules.StringMaxLength, new CommonRules.MaxLengthRuleArgs("ContributionName", 100));

to check the length.

please suggest.

RockfordLhotka replied on Thursday, January 28, 2010

You should read chapters 1-5 of Expert 2008 Business Objects to get a good understanding of the way the framework supports objects.

In smart client technologies (everything but ASP.NET) the CSLA validation model causes most rules to run on the client. You have to do something specifically different if you want a rule to run on the app server.

In the web things are different. This is because the web technologies are really quite poor for business app development. In the web, your .NET code can't run in the browser - pretty much by definition...

The easiest and cheapest solution is to use Silverlight, because that lets you create a "web app" that is really a smart client.

But if you can't do that, the next best thing is probably to use ASP.NET MVC 2 (which isn't out yet unfortunately), because MVC 2 will automatically project client-side script code into the web page based on validation attributes on your object properties.

And if you can't do that, then you might look at ASP.NET MVC 1, along with one of the open source projects out there that projects client-side script into the web page based on attributes on your object properties.

And if you can't do that, then you'll need to create some ASP.NET Web Forms code to project validation controls into the web form based on the rules defined in your object.

To make this possible, CSLA .NET allows you to ask an object for its list of rules. You'll get back a list of rule:// URI values, and there's a RuleDescription type that helps you parse those URI values into useful information (like System.Uri, but more specialized).

bharat0204 replied on Friday, January 29, 2010

Thanks you very much for your instant reply.

sorry but as suggested by you i cant implement any of that new way as the project is almost completed and going live by next month.
the only remaining is some validation on which i am working and come across above senerio mentioned.

also i m new to CSLA as well so not much familiar about the concept. i watched your video and gone through the book and come across some fundamentals of CSLA.

so now just i saw the implemented validation rule in my current project which struck me so i asked about the best way to achieve this.

so if you please suggest me some way to achieve without lots of changes and less time then it is great to me.

looking for your suggestion.

thanks in advance.

RockfordLhotka replied on Friday, January 29, 2010

Are you building a Web Forms user interface?

If yes, then you only have two options:

  1. Manually add validator controls to your UI - duplicating the validation logic from your business objects
  2. Write code to automatically insert validator controls in your UI based on the rule:// URI information from the business object

 

Copyright (c) Marimer LLC