Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Integrating BLL Validation with ObjectDataSource and Gridview

Reply
Thread Tools

Integrating BLL Validation with ObjectDataSource and Gridview

 
 
JimLad
Guest
Posts: n/a
 
      01-26-2010
Hi,

ASP.NET 3.5

I've recently been struggling with BLL Validation and when and where I
should do it.

I have a Gridview using an ObjectDataSource. This is a standard thing
that I'll be doing on loads of pages and I will be creating a
template
for this.

Obviously I can validate in the Gridview_Updating event. However,
nothing is typed at this point so I would have to type everything
manually. Values are typed in ObjectDataSource_Updating, but by then
I've lost the e.cancel function and would have to raise an exception
to cancel.
Returning to Gridview_Updating I can pass the typed values I need
individually or I can pass the IOrderDictionary of values, newvalues
or keys. However these are untyped and I would have to them type them
in the BLL layer so I've rejected this option.

Or I can Validate in the BLL layer in the Update function (called by
UpdateMethod of the ObjectDataSource). I have a Generic List of
validation failures to return and I also want to keep
the entered values on the page, not refresh the page if there are
validation problems. The only way to prevent the page from refreshing
seems to be to return an exception to GridView_Updated. I could
create
a new Exception which contains the Validation Error Generic List. But
I have always thought that Exceptions should not be raised for
standard functionality like this?

Basically I want to limit bespoke validation functionality to the BLL
layer and not have to do manual typing on the UI layer. But I can't
seem to find a way of doing that without raising exceptions.

Any advice would be very welcome. If these are the only 2 options,
which should I do? I realise it would take very little effort to type
values manually on the UI side for each page, but I always like to
standardise code where possible.

James
 
Reply With Quote
 
 
 
 
Alvin Bruney - ASP.NET MVP
Guest
Posts: n/a
 
      02-01-2010
The problem is with the design, objectdatasource is not a Business layer.
It's a provider that knows how to talk to the data store. If you had a true
business layer, it would sit in between the gridview and the datasource. At
that point, your problems would go away.

>I could
> create
> a new Exception which contains the Validation Error Generic List. But
> I have always thought that Exceptions should not be raised for
> standard functionality like this?

This is the absolute correct way to do this - use the exception mechanism,
which represents a failed validation. This is a best practice. [This is also
how dynamic data works with the entity model so you should pattern against
this approach]. The idea is that if the user enters incorrect input, the
Business layer should blow up and stop right there. An exception represents
just that.

No real good solution for the typing problem because of the tight coupling
between the gridview and the objectdatasource container. you may have to get
clever with some of the events that are exposed in the gridview and
objectdatasource. Btw, binding a gridview to an objectdatasource is often
done because it is easy for trivial situations. You start running into
issues when the software you are building gets complicated.

--
Vapordan
Shameless Author Plug
ASP.NET 4 by Example only $20
OWC Blackbook www.lulu.com/owc

"JimLad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> ASP.NET 3.5
>
> I've recently been struggling with BLL Validation and when and where I
> should do it.
>
> I have a Gridview using an ObjectDataSource. This is a standard thing
> that I'll be doing on loads of pages and I will be creating a
> template
> for this.
>
> Obviously I can validate in the Gridview_Updating event. However,
> nothing is typed at this point so I would have to type everything
> manually. Values are typed in ObjectDataSource_Updating, but by then
> I've lost the e.cancel function and would have to raise an exception
> to cancel.
> Returning to Gridview_Updating I can pass the typed values I need
> individually or I can pass the IOrderDictionary of values, newvalues
> or keys. However these are untyped and I would have to them type them
> in the BLL layer so I've rejected this option.
>
> Or I can Validate in the BLL layer in the Update function (called by
> UpdateMethod of the ObjectDataSource). I have a Generic List of
> validation failures to return and I also want to keep
> the entered values on the page, not refresh the page if there are
> validation problems. The only way to prevent the page from refreshing
> seems to be to return an exception to GridView_Updated. I could
> create
> a new Exception which contains the Validation Error Generic List. But
> I have always thought that Exceptions should not be raised for
> standard functionality like this?
>
> Basically I want to limit bespoke validation functionality to the BLL
> layer and not have to do manual typing on the UI layer. But I can't
> seem to find a way of doing that without raising exceptions.
>
> Any advice would be very welcome. If these are the only 2 options,
> which should I do? I realise it would take very little effort to type
> values manually on the UI side for each page, but I always like to
> standardise code where possible.
>
> James


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ObjectDataSource not calling BLL Tides ASP .Net 3 04-27-2008 11:12 PM
Automatically generate BLL for ObjectDataSource? tomerdr@gmail.com ASP .Net 0 04-28-2007 01:59 PM
BLL and WebService Stan SR ASP .Net 2 11-29-2006 07:50 AM
BLL and DAL. Roy ASP .Net 10 06-16-2006 08:01 PM
Integrating xhtml/html validation into a web-based CMS(MS-windows) Spam Survivor XML 3 09-15-2003 06:29 PM



Advertisments