PDA

View Full Version : How-to: a child Page inject into TWO parent pages


crabo
11-07-2005, 02:04 AM
Even I have check most of the master-page topic, I have no idea of
Inject one child into two parent

<object id="Parent1" type="~/Parent1.aspx" />
<object id="Parent2" type="~/Parent2.aspx" />
<object id="Child" type="~/Child.aspx" parent="Parent1"/>

Thanks!

Aleks Seovic
11-08-2005, 03:01 AM
Can you explain in more detail what you are trying to accomplish. I'm not really following your example.

- Aleks

crabo
11-08-2005, 05:03 AM
I have a page, about cargo.
when a ShipBroker comes to the system, he want the cargo shows with the FixtureNote,;
when a Operator comes to the system, he want the cargo shows with the VoyageSchedule;

so, the cargo page, should be show in the other 2 pages.

now I use <IFRAME/> to achive that.

how about inject?

Aleks Seovic
11-08-2005, 05:14 AM
Why don't you create a user control for cargo and reuse it within as many pages as you want?

This is not a problem master pages were designed to solve.

- Aleks

crabo
11-08-2005, 09:27 AM
the cargo page is a comparatively complex one.
it has it's own FORM,own Code-Behinde events.

also it was created by other guy of our team.
move it to a user-control is really a big job.

Aleks Seovic
11-08-2005, 02:13 PM
It's usually smaller job than it seems -- renaming file to .ascx, making it extend UserControl instead of a Page, getting rid of unnecessary markup (including form tag, which should only be defined once on the page), and rethinking control's API (maybe adding few properties and/or events that can be used by the hosting page) is usually all it takes to convert page to a user control. This is by far the best way to accomplish what you need and encapsulate reusable piece of UI functionality.

That said, it is possible to apply two different master pages to the same page, you just need to define two child definitions:


<object id="ShipBrokerMaster" type="~/ShipBrokerMaster.aspx" />
<object id="OperatorMaster" type="~/OperatorMaster.aspx" />

<object id="ShipBrokerCargo" type="~/Cargo.aspx">
<property name="Master" ref="ShipBrokerMaster"/>
</object>

<object id="OperatorCargo" type="~/Cargo.aspx">
<property name="Master" ref="OperatorMaster"/>
</object>


Now you can simply access your cargo page using ShipBrokerCargo.aspx or OperatorCargo.aspx in the URL.

Keep in mind that, as I said earlier, this is really not what master pages were designed for, and is not how I recommend using them.

Regards,

Aleks

crabo
11-10-2005, 01:29 AM
Thank you :D


<object id="ShipBrokerCargo" type="~/Cargo.aspx">
<property name="Master" ref="ShipBrokerMaster"/>
</object>

<object id="OperatorCargo" type="~/Cargo.aspx">
<property name="Master" ref="OperatorMaster"/>
</object>
But isn't the objectId should be same as the page'name?

<object id="Cargo" type="~/Cargo.aspx">

Aleks Seovic
11-10-2005, 02:57 AM
Not necessarily -- you can give any ID to object definitions, including page definitions, as long as it is unique within the context.

If you don't specify ID attribute for the page it will default to the name of the page file (without the extension), but nothing prevents you from setting it to something else. What is important to understand is that Spring uses ID to find the object in the context, so you will have to use ShipBrokerCargo.aspx and OperatorCargo.aspx within your URLs as appropriate.

This feature comes very handy in situations when you want to display same page in several different ways. For example, let's say that you have an Employee.aspx page that you want to display in both editable and read-only format.

What you could do is expose Editable (or ReadOnly) property on the page and create two definitions for the same page:


<object id="EditEmployee" type="Employee.aspx">
<property name="Editable" value="True"/>
</object>

<object id="ViewEmployee" type="Employee.aspx">
<property name="Editable" value="False"/>
</object>


Your Employee.aspx would simply check the value of the property and make input controls read-only or disabled if Editable property is set to False.

Then you could even set up security in such a way that only certain users have access to EditEmployee.aspx and that nobody can access Employee.aspx directly, because ASP.NET security is based on URLs, not physical page files.

Anyway, I hope this clarifies my previous post.

Regards,

Aleks

crabo
11-10-2005, 07:12 AM
ya! very clear now.

and also corrected my misunderstand....