ASP.NET multiple pages with very similiar layout and logic

G

Greg

I have a complex page (with 8 complex user controls, and many other
asp.net controls.) I have 2 very similiar pages to create, each page
differing only from the others in one control.

What is the best way to achieve this? I would guess that I have 3
alternatives.
1.) Visual and Logic inheritance. I know absolutely nothing about this
in ASP.NET, and I haven't found anything that appears immediately
simple ( i am in a rush to get this job done!).
2.) Have one page with all the controls on, and pass a parameter in
the request for the page informing it which identity it should assume
- i..e. if "PageA" is sent in the page request, the page should behave
like and contain the controls of a "PageA" type page, etc... This
would appear simple, though the different pages are to have different
security permissions - I intended for each page to be in its own
folder with the web.config file for that folder definining the access
rights for the logged in user. Having one page to do the work of 3
would mean that I would have to do the configration work in the top
level web.config file, which seems a bit more onerous.
3.) Put the contents of the page I have in now into a user control,
and put this user control into 3 different pages. My main worry about
this is the degree of processing overhead involved at the server,
since the control would be complex (many controls + 8 user controls
within it). However, it would mean that I could have 3 distinct pages
that I could more easily apply user access rights to.

I'm from a winforms background, so a lot of the concepts are quite new
to me - I'd appreciate any feedback on this.

Regards,

Greg.
 
M

Mark Rae

I'm from a winforms background, so a lot of the concepts are quite new
to me - I'd appreciate any feedback on this.

Sounds like a prime candidate for MasterPages:
http://www.google.co.uk/search?sour...G,GGLG:2006-28,GGLG:en&q="ASP.NET"+MasterPage

In a nutshell, MasterPages allow the main "look and feel" of a web app to be
written once only (in the MasterPage itself), and then indivual content
pages to be created which contain the bits which are different...

Prior to ASP.NET v2, this sort of functionality was commonly achieved with
user controls e.g. a user control for the header, a user control for the
menu, another for the sidebar, maybe another for the footer etc. References
to these controls needed to be added to each aspx page that required them.

MasterPages do away with all that. Once the MasterPage is created, simply
create a new content page and set its MasterPage property - job done.
 
G

Greg

Sounds like a prime candidate for MasterPages:http://www.google.co.uk/search?sourceid=navclient&ie=UTF-8&rls=GGLG,G...

In a nutshell, MasterPages allow the main "look and feel" of a web app to be
written once only (in the MasterPage itself), and then indivual content
pages to be created which contain the bits which are different...

Prior to ASP.NET v2, this sort of functionality was commonly achieved with
user controls e.g. a user control for the header, a user control for the
menu, another for the sidebar, maybe another for the footer etc. References
to these controls needed to be added to each aspx page that required them.

MasterPages do away with all that. Once the MasterPage is created, simply
create a new content page and set its MasterPage property - job done.

Thanks Mark.

Under the given circumstances, what advantage would a master page have
over a user control?

The control that is different in the 3 pages is half way down the
page. Would it be necessary to have 2 master pages - i.e. one for the
top half of controls, and one for the bottom half, and the control
that is to be different in between?

Regards,

Greg.
 
M

Mark Rae

Under the given circumstances, what advantage would a master page have
over a user control?

In fact, a MasterPage is nothing more than a user control anyway...
The control that is different in the 3 pages is half way down the
page.
OK.

Would it be necessary to have 2 master pages - i.e. one for the
top half of controls, and one for the bottom half, and the control
that is to be different in between?

Not at all. The MasterPage would contain the "top half" and "bottom half".

The content pages would contain the content which changes.
 
G

Guest

There are 2 ways to achieve this with masterpages.

1. Have nested master-pages (one within another). You can choose the correct
master page to suit your needs then. The bad part about this is that you
won't have any designer support on this.
2. Have multiple contentplaceholder's in the same master page. That way, at
every page you can have complete control on what goes into the content, and
what gets inherited from the masterpage.

Having mutiple masterpages, for one page is kind of a bad way to program for
uniform look and feel. I suggest in your case, you may as well use multiple
contentplaceholder's in the same masterpage.

Regarding the advantage of masterpages over user-controls, well...all i
know/can say about masterpages is that its optimized , since its a part of
the framework. In the past, I have created the master-page as a usercontrol
(in asp.net 1.1), and the drawback in my code was that for some reason, it
took longer to render each time, and there was less of
programmer-friendliness.

Hope that helps,
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top