Web and Business Objects...how to tie them together

R

Relaxin

I have created my own business objects with both a Collection class and a
record class.

When I use the ObjectDataSource (ODS) it requires a SelectMethod from the
Collection class.
My first try I made this a static function within my collection class, but
the ODS_ObjectCreated event won't fire. (very strange design)
So I changed it to a regular class function, where the class has to be
instantiated in order to be use it. (I don't get this...why the need to
instantiate a class to call a function within that class to instantiate the
SAME class again!!....again, a very strange design).

Back to my issue...

All I have on my web form is a gridview and an ODS.

I created my collection and stored it in a session variable.

[1] if(!IsPostBack)
{
if(Session["Receipt"] == null)
{
m_ReceiptCollection = new ReceiptLinesCollection();
Session["Receipt"] = m_ReceiptCollection;
}
m_ReceiptCollection =
(ReceiptLinesCollection)Session["Receipt"];
}

I reuse this object for the ODS to use.
[2] protected void ObjectDataSource1_ObjectCreated(object sender,
ObjectDataSourceEventArgs e)
{
m_ReceiptCollection = (ReceiptLinesCollection)Session["Receipt"];
e.ObjectInstance = m_ReceiptCollection;
}

The creation of my Business Object(BO) causes 2 records to be loaded into
it.

When I load the web page my Postback code is ran and my collection is
created as you can see above[1].
And thru debugging I see that my BO is created again for the ODS to
use...but I'm assigning it the object that I want it to use...see above[2].
*1* I can't find any other way to assign the ODS a preallocated BO to use,
the only way is thru the ObjectCreated event.

When I click the "Edit" link on the grid, it once again creates another BO!

Then I edit one of the fields and then click "Update". It creates another BO
to call the UpdateMethod to send me a collection record.

*2* This is what I don't get, the ODS has the collection list [2], but it
won't update the record in the list, but instead sends me a brand new record
for me to place in the list. But guess what, the UpdateMethod doesn't know
what list to update because all it has is an orphaned record with no parent
(Collection).

Can someone PLEASE help me to understand this convoluted design with issues
*1* and *2*?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top