Help executing an IF TEST within MASTERPAGE, please

S

simon

Hello,
I'm helping write a .net app, we are using VS2005 and asp/vb.net for
code
we are using the "masterPage.master" technique, within the masterpage
we have an asp:contentplaceholder that is the place holder for the
main portion of the body of the site

my question is, is there a way to test what aspx page will be loaded
into the contentplaceholder? basically if it is our home page, that
page has a wider definition than all of our other pages. so i'd like
to test in the masterpage and if it is home.aspx then use a certain
layout, if it is anything else, then i'd like to use an alternate
layout.

any suggestions (or code examples) would be most appreciated. i'm
relatively new to .net, but have been coding for many years prior
thanks, simon
 
S

Slim

My advice is not to use Master pages, as they rename tags and make scripting
more difficult.

I use includes, putting your CSS links and whatever in the headPage and
header and footer in top and bottom pages.

you can the save page as a template

<HTML>
<HEAD>
<!-- #include virtual ="/headPage.aspx" -->
</HEAD>
<BODY>
<!-- #include virtual ="/top.aspx" -->

Content here


<!-- #include virtual ="/bottom.aspx" -->
</BODY>
<HTML>
 
S

simon

thanks for the reply, being relatively new, i do not know how to do
that. could you expand on your answer if you don't mind. thanks
 
S

simon

I'm with you there. i've run into exactly what you've said that makes
using it more difficult. right now i don't have an option to (due to
time) to undo the usage of masterpage. so i'm hoping there is
something programmatically i can use to fix this issue.
 
A

Alan Silver

Slim <[email protected]> said:
My advice is not to use Master pages, as they rename tags and make
scripting more difficult.

My advice is definitely to use master pages as they are a fantastic boon
for web sites. You just have to learn how to get around the fact that
the client ID of controls is changed to cope with the fact that you
could easily have two controls with the same ID, one in the master page
and one in a content area (etc).

If you are bothered about client-side scripting, then all you need to do
is something like...

<script type="text/javascript">
function something() {
myName = <%= txtMyName.ClientID %>.value;
}
</script>

When the page is compiled, the server-side bit of the above code is
replaced with the generated client ID, and your javascript works fine.

The same can be done for the "for" attribute of <label> tags.

Include files are a very poor and non-OO way of doing templates for your
site. Master pages have many, many advantages.
 
A

Alan Silver

simon said:
my question is, is there a way to test what aspx page will be loaded
into the contentplaceholder? basically if it is our home page, that
page has a wider definition than all of our other pages. so i'd like
to test in the masterpage and if it is home.aspx then use a certain
layout, if it is anything else, then i'd like to use an alternate layout.

Depends exactly what you need to do. For example, I have a situation
where one page needs a slightly different layout from the others. I have
two contentplaceholder controls in the master page, one inside the
<head> and one in the <body>.

The one in the <head> is rarely used, but in the page mentioned above,
it contains a few lines of CSS that set the layout specific to this
page. Remember, this page-specific CSS is not set in the master page, it
is in the content (.aspx) page.

If you really need to get at the name of the content page from within
the master page, use (air code, check the exact syntax)...

Request.ServerVariables["SCRIPT_NAME"].ToString()

which will give you the name of the .aspx file.

HTH
 
S

Slim

Alan Silver said:
My advice is definitely to use master pages as they are a fantastic boon
for web sites. You just have to learn how to get around the fact that
the client ID of controls is changed to cope with the fact that you
could easily have two controls with the same ID, one in the master page
and one in a content area (etc).

If you are bothered about client-side scripting, then all you need to do
is something like...

<script type="text/javascript">
function something() {
myName = <%= txtMyName.ClientID %>.value;
}
</script>

When the page is compiled, the server-side bit of the above code is
replaced with the generated client ID, and your javascript works fine.

The same can be done for the "for" attribute of <label> tags.


why bother?

when you can simply do this below, get same result without the bother. you
can save it as a template

<HTML>
<HEAD>
<!-- #include virtual ="/headPage.htm" -->
</HEAD>
<BODY>
<!-- #include virtual ="/top.htm" -->

Content here


<!-- #include virtual ="/bottom.htm" -->
</BODY>
<HTML>
 
A

Alan Silver

Slim <[email protected]> said:
why bother?

when you can simply do this below, get same result without the bother.
you can save it as a template

Because with master pages you only have one template file instead of
three, you have a single, central place where your template coding can
take place, you have real OO access to the elements on your page and
many, many more reasons.

Sure you can use include files, but then you can use Response.Write to
generate your HTML if you want. MS don't force you to use the new
methods, but you are missing a lot if you stick with the old, outdated
way of doing things. It looks to me like you are still thinking in
calssic ASP mode.

I also used to think like you about master pages. That was before I
understood what they are and how they work. I came from classic ASP and
was trying to force ASP.NET into that programming model. You can do it
that way, but you miss many of the benefits of the new framework. If you
take time to learn the ASP.NET way of doing things, you'll find yourself
much more productive in the long run.

Just my 2c.
 
S

Slim

Alan Silver said:
Because with master pages you only have one template file instead of
three,

i think yo miss my point, the page i posted is a example, of cause i still
use the vb code behind and all the other features of .net. I just dont like
the way master pages change id names

you use the page i posted as 1 template. not 3,


you have a single, central place where your template coding can
take place, you have real OO access to the elements on your page and many,
many more reasons.

Objects can be placed in the page no probs, i cant see the diff
Sure you can use include files, but then you can use Response.Write to
generate your HTML if you want. MS don't force you to use the new methods,
but you are missing a lot if you stick with the old, outdated way of doing
things. It looks to me like you are still thinking in calssic ASP mode.

I also used to think like you about master pages. That was before I
understood what they are and how they work. I came from classic ASP and
was trying to force ASP.NET into that programming model. You can do it
that way, but you miss many of the benefits of the new framework. If you
take time to learn the ASP.NET way of doing things, you'll find yourself
much more productive in the long run.

Just my 2c.

What benefits?
how would it be more productive?
 
A

Alan Silver

Slim <[email protected]> said:
i think yo miss my point, the page i posted is a example, of cause i still
use the vb code behind and all the other features of .net. I just dont like
the way master pages change id names

For that one small disadvantage you throw out master pages? That's like
dumping the Ferrari because the ashtrays are too small!!

By the way, you can get around the ID names easily. It's only an issue
with client side validation, and all you need to do there is write the
control's ClientID into the Javascript. Very simple and removes the one
disadvantage of master pages.
you use the page i posted as 1 template. not 3,

Your template required three include files to build the basic structure
of the page. Master pages only require one.

More to the point, your method requires you to add the three include
directives to every page on the site. If you change the structure of the
template, you may end up having to go through every page on the site and
update the include directives. With master pages you only have one
single file that needs changing. All content pages that use that master
remain untouched. That's a huge advantage.
you have a single, central place where your template coding can

Objects can be placed in the page no probs, i cant see the diff

That's not what I meant. With master pages, you have a concise object
model for the whole page. With your method you don't. There's no clear
structure to the page. One include file won't necessarily know what's in
the others, so won't be able to access the controls there without some
fiddling. Master pages give you a unified object model for the complete
page.
What benefits?
how would it be more productive?

Reread my posts and see. If you've ever tried to update a large site
that uses include files, you'll know what a major pain this can be. I
used to do it that way with Classic ASP and started doing ASP.NET that
way until I realised that I was missing a huge benefit that master pages
brought. I have since done major site updates by changing one single
file, taking a few moments, as opposed to a large headache having to
change hundreds of files, with all the potential for errors that this
causes.

I'm not going to argue this further. I understand where you are coming
from as I have been there myself. Most of us that came from classic ASP
(or other environments) went through similar stages of trying to fit the
old model into ASP.NET, whilst not realising the major benefits of the
newer ways of doing things. I reckon if you tried using master pages,
and worked through a decent sized site with them, you'd never go back to
include files.

Ta ra
 
S

Slim

Alan Silver said:
For that one small disadvantage you throw out master pages? That's like
dumping the Ferrari because the ashtrays are too small!!

By the way, you can get around the ID names easily. It's only an issue
with client side validation, and all you need to do there is write the
control's ClientID into the Javascript. Very simple and removes the one
disadvantage of master pages.


A major disadavantage

Your template required three include files to build the basic structure of
the page. Master pages only require one.

More to the point, your method requires you to add the three include
directives to every page on the site. If you change the structure of the
template, you may end up having to go through every page on the site and
update the include directives.

why would you change the structure, you would change the include pages not
the structure

while some times you may want to, you can give one page a different include,
a advantage over master pages


With master pages you only have one
single file that needs changing. All content pages that use that master
remain untouched. That's a huge advantage.


as with includes


That's not what I meant. With master pages, you have a concise object
model for the whole page. With your method you don't. There's no clear
structure to the page. One include file won't necessarily know what's in
the others, so won't be able to access the controls there without some
fiddling. Master pages give you a unified object model for the complete
page.

no you can load any shared objects into the template, no need to put them
into a include
Reread my posts and see. If you've ever tried to update a large site that
uses include files, you'll know what a major pain this can be. I used to
do it that way with Classic ASP and started doing ASP.NET that way until I
realised that I was missing a huge benefit that master pages brought. I
have since done major site updates by changing one single file, taking a
few moments, as opposed to a large headache having to change hundreds of
files, with all the potential for errors that this causes.

just as I have, but making a few minor changes to a include

I'm not going to argue this further. I understand where you are coming
from as I have been there myself.

I don't believe you have



Most of us that came from classic ASP
(or other environments) went through similar stages of trying to fit the
old model into ASP.NET, whilst not realising the major benefits of the
newer ways of doing things.

i agree ASP.NET has more to offer than asp in certain circustances, but ASP
still has its place, and insome ways is far better tool to use.

I reckon if you tried using master pages,
and worked through a decent sized site with them, you'd never go back to
include files.


you are entitled to your opinion
i tend to disagree.

PS I would use master pages where i find them of more use, I would not say
never.
 

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,139
Latest member
JamaalCald
Top