"Fresno Bob" <> wrote in message
news:...
> What is the best approach?
There isn't one - as with virtually everything in ASP.NET, it comes down to
personal preference...
I agree with you about not having separate forms for inserting and
updating - I never do that. Generally speaking, I use two forms for each
business "object" / "entity" / whatever. E.g. if I need to maintain
customers, then I'll have a customers.aspx page which lists existing
customers in a GridView to allow the user to do all the sorting, paging,
filtering, searching etc. The GridView will be databound to a DataSet
fetched from my DAL, which uses a factory pattern based on the Microsoft
DAAB.
Typically, users create a new customer by clicking on a "New" button, or
edit an existing customer simply by clicking on a row in the GridView. Both
of these actions redirect to the customer.aspx page, which works out whether
the user wants to create a new customer or edit an existing one depending on
whether it has been passed a customer identifier or not.
Typically, there will be a Save button which will work out whether to insert
a new record or update an existing one in the same way. Either action, if
successful, will redirect the user back to the customers.aspx page.
The customer.aspx page will often have dropdowns etc - I populate those via
databinding. However, I never databind the actual record itself. Instead, I
fetch it out of the database via my DAL and populate the form objects
manually. There may or may not be a Customers class - that will depend on
various factors, but mainly on how "reusable" the whole concept of a
"customer" needs to be in the particular web application. There's a whole
ream of nonsense spouted about how the world will end if you use ADO.NET
objects (e.g. DataSets, DataReaders etc) directly in your codebehind - OOP
is fundamental to .NET programming, of course, and quite rightly so, but
care needs to be taken not to get anal about it. If you need a class, write
a class - if you don't, then don't...
Similarly, I never use the SqlDataSource objects or the validation controls.
That doesn't mean that I'm against innovation - quite the contrary. Each new
version of the Framework has brought some fantastic stuff with it, e,g,
generics in v2 and LINQ in v3.5, but "new" and "quick" and "easy" don't
always mean "good", IMO...
There will no doubt be people sniggering at this, or throwing their arms up
in disbelief...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net