468,168 Members | 1,649 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,168 developers. It's quick & easy.

Saving the page from footer user control

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
Feb 24 '07 #1
5 1245
Hi,

Annie wrote:
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
Feb 24 '07 #2
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 [MVP]" <ga*********@bluewin.chwrote in message
news:u7***************@TK2MSFTNGP02.phx.gbl...
Hi,

Annie wrote:
>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

Feb 24 '07 #3
Hi Annie,

Annie wrote:
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/lib...trol.page.aspx

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
Feb 24 '07 #4
Annie wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Feb 24 '07 #5
Hi,

Göran Andersson wrote:
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
--
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
Feb 24 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.