Saving the page from footer user control

A

Annie

hello guys,

I have a scenario that I am confused about ...

I have a number of pages which are using a Master page ...

Then I have seperate Footer user control that can reside in master page or
could be kept
in the content pages (still not confirmed and looking for any suggestion)

The challenge is that when the user presses the Save button within the user
control
the content of the pages needs to be saved ... I am using Strongly typed
datasets
as Data layer and there Business Objects in the middle of the pages and the
Data Layer

The challenge is that the footer should raise the save event and save the
content of the
pages independently ... I mean each page could be bound to a different
Business Object
and obviously its own Data Layer.

What is the best way to do it in this way?
Any suggestion will be appreciated?
Is there any example code available?

TA
 
L

Laurent Bugnion [MVP]

Hi,
hello guys,

I have a scenario that I am confused about ...

I have a number of pages which are using a Master page ...

Then I have seperate Footer user control that can reside in master page or
could be kept
in the content pages (still not confirmed and looking for any suggestion)

The challenge is that when the user presses the Save button within the user
control
the content of the pages needs to be saved ... I am using Strongly typed
datasets
as Data layer and there Business Objects in the middle of the pages and the
Data Layer

The challenge is that the footer should raise the save event and save the
content of the
pages independently ... I mean each page could be bound to a different
Business Object
and obviously its own Data Layer.

What is the best way to do it in this way?
Any suggestion will be appreciated?
Is there any example code available?

TA

With a situation like this, where an object (the footer) needs to send
an order to a different object (the page) without knowing exactly how
the order is going to be executed, you need a basic contract between
these two objects. The footer needs to know that if he sends a "Save"
order, the page is going to understand it. The footer doesn't need to
know more, because how each page saves itself is the page's responsibility.

The best way to do this in an object-oriented world is to use
interfaces. Have the Pages implement an interface specifying that there
is a "Save" method. The interface doesn't say more, it just allows the
footer control to take the page it is included in (each control has a
this.Page property) and then cast it to the corresponding ISaveable
interface. Note: You want to have that in a try/catch block in case the
footer is included in a page which cannot be saved.

Then, if the cast is successful, the footer knows for sure that there is
a "Save" method available.

In order to handle the common operations involved in a "Save" operation,
you can create a basic class for the pages. So the structure would be:

Page
|
SaveablePage
|
MyOwnPage

Additionally, MyOwnPage implements ISaveable.

The advantage of having the footer handle ISaveable objects rather that
SaveablePage objects is that this is more flexible, this is a less
strong relationship.

Does it make sense?
Greetings,
Laurent
 
A

Annie

Dear Laurent,

Thank you very much for your reply.

I think you fully understand my problem. I fully understand you explanation.
I had a similar structure already.
The problem I had was I didn't know how to call the page from the Footer
user control ...

I think the trick was "this.Page" property ... just handling that event and
it worked perfectly! ...I much appreciate
your hint.

regards




Laurent Bugnion said:
Hi,
hello guys,

I have a scenario that I am confused about ...

I have a number of pages which are using a Master page ...

Then I have seperate Footer user control that can reside in master page
or could be kept
in the content pages (still not confirmed and looking for any suggestion)

The challenge is that when the user presses the Save button within the
user control
the content of the pages needs to be saved ... I am using Strongly typed
datasets
as Data layer and there Business Objects in the middle of the pages and
the Data Layer

The challenge is that the footer should raise the save event and save the
content of the
pages independently ... I mean each page could be bound to a different
Business Object
and obviously its own Data Layer.

What is the best way to do it in this way?
Any suggestion will be appreciated?
Is there any example code available?

TA

With a situation like this, where an object (the footer) needs to send an
order to a different object (the page) without knowing exactly how the
order is going to be executed, you need a basic contract between these two
objects. The footer needs to know that if he sends a "Save" order, the
page is going to understand it. The footer doesn't need to know more,
because how each page saves itself is the page's responsibility.

The best way to do this in an object-oriented world is to use interfaces.
Have the Pages implement an interface specifying that there is a "Save"
method. The interface doesn't say more, it just allows the footer control
to take the page it is included in (each control has a this.Page property)
and then cast it to the corresponding ISaveable interface. Note: You want
to have that in a try/catch block in case the footer is included in a page
which cannot be saved.

Then, if the cast is successful, the footer knows for sure that there is a
"Save" method available.

In order to handle the common operations involved in a "Save" operation,
you can create a basic class for the pages. So the structure would be:

Page
|
SaveablePage
|
MyOwnPage

Additionally, MyOwnPage implements ISaveable.

The advantage of having the footer handle ISaveable objects rather that
SaveablePage objects is that this is more flexible, this is a less strong
relationship.

Does it make sense?
Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
L

Laurent Bugnion [MVP]

Hi Annie,
Dear Laurent,

Thank you very much for your reply.

I think you fully understand my problem. I fully understand you explanation.
I had a similar structure already.
The problem I had was I didn't know how to call the page from the Footer
user control ...

I think the trick was "this.Page" property ... just handling that event and
it worked perfectly! ...I much appreciate
your hint.

regards

Glad to be of help. "this.Page" is not an event, it's a property of the
System.Web.UI.Control class of which your footer control derives. It's
populated as soon as the control is added to a Page.

http://msdn2.microsoft.com/en-us/library/system.web.ui.control.page.aspx

Greetings,
Laurent
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Annie said:
hello guys,

I have a scenario that I am confused about ...

I have a number of pages which are using a Master page ...

Then I have seperate Footer user control that can reside in master page or
could be kept
in the content pages (still not confirmed and looking for any suggestion)

The challenge is that when the user presses the Save button within the user
control
the content of the pages needs to be saved ... I am using Strongly typed
datasets
as Data layer and there Business Objects in the middle of the pages and the
Data Layer

The challenge is that the footer should raise the save event and save the
content of the
pages independently ... I mean each page could be bound to a different
Business Object
and obviously its own Data Layer.

What is the best way to do it in this way?
Any suggestion will be appreciated?
Is there any example code available?

TA

Create an event in the control, and let the page register an event
handler to the event.

That is how controls usually communicate something like this to the
page, like for example the Click event of a Button control.
 
L

Laurent Bugnion [MVP]

Hi,

Göran Andersson said:
Create an event in the control, and let the page register an event
handler to the event.

That is how controls usually communicate something like this to the
page, like for example the Click event of a Button control.

Funny, I am in the course of writing an article for my blog about the
advantages and inconveniencies of interface methods versus events, and
didn't even think of mentioning events to the OP.

Of course events are a great way to solve that particular problem. They
create one dependency less, since the event thrower (the footer) doesn't
need to know anything about the event catcher (the Page). So it's more
flexible.

HTH,
Laurent
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top