MasterPage changing Content Page

  • Thread starter Thread starter pvong
  • Start date Start date
P

pvong

Doing this in VB.NET

This is my first attempt and it didn't work. I have a simple master page
with a DropDownList. All I want it to do is if DropDownList SelectedValue =
"2" then the content page opens up another page. I hope this makes sense.
Anyway, this was my code:

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

If DropDownList1.SelectedValue = "2" Then

ContentPlaceHolder1.ResolveUrl("http://somesite.com")

End If

End Sub
 
Go into design view and double-click on the DropDownList control. Visual
Studio will generate an event handler in your .vb file. In that event
handler write your code to navigate to the page you want using one of
several means to transfer control to a new page; Transfer or Redirect
depening on how you want to handle the URL displayed in the browser's
address bar. The other stuff Rae discussed I tend to agree with except to
note MasterPage is not a user control but a type of user control as there is
a difference between "is a" and "type of". The use of an iFrame is not
needed.

That said, if you actually want to load the same content page using a
different look and feel you will need to call itself using a different
MasterPage which must be done using a base class so you can access the
Page_PreLoad event otherwise not accessible to the MasterPage or the Content
Page because Master is a "type of" User Control as I've made a brief attempt
to clarify.
 
Mark Rae said:
Ignore the above - a MasterPage is a UserControl.

A more detailed answer could be that OO design is based on the assumption
that any (sub)Type of X is an X (see Liskov Substitution Principle).
 
Yes, I mispoke when stating Page_PreLoad when in fact the event is
Page_PreInit which brings me to ask for clarification from those who
proclaim themselves as experts --must-- we use a base class and Page_PreInit
to access and change properties of a User Control in a Content Page when
using a MasterPage?
 
Hello Christophe.
Is a dog also a human being because we both have legs or are we both a type
of mammal?
 
Hillbilly said:
Hello Christophe.
Is a dog also a human being because we both have legs or are we both a
type of mammal?

Hey, nothing personal, i just wanted to say something about "a MasterPage is
a UserControl"...

.... with the secret wish to avoid polemics.

My bad ;)

"Is" has a lot of different meanings. In OO stuff, it means something
specific, and i was hoping that reminding this specific meaning could help
everybody to agree.
 
Hillbilly said:
Hello Christophe.
Is a dog also a human being because we both have legs or are we both a
type of mammal?

Accroding to the C# language
if (MasterPage is UserControl)
will evaluate to true... So MasterPage is a UserControl :)

And (from MSDN) the hierarchy goes.
System.Object
System.Web.UI.Control
System.Web.UI.TemplateControl
System.Web.UI.UserControl
System.Web.UI.MasterPage


Not sure about dogs being humans :)


George.
 
I am formally educated, degreed and an experienced architect. On the basis
of my training if I were to make decisions on what is mearly implied as you
all have done in this matter by continually referring to nothing more than
the a listed item in an inheritance tree people could lose their lives.

Therefore I have been compelled to become a strict constructionist. Other
than the fact that the MasterPage and the User Control both inherit from the
Template Control Class I have yet to read one word of official documentation
that explicitly states the MasterPage --is a-- User Control. Furthermore,
there is so much documentation stating otherwise not to mention how
different each is in usage that I have been surprised people continue to
insist on claiming --is a-- rather then the more correct --type of--
description.

I'm going to write to Scott Gu and ask him if he will finally blog on this
matter as it keeps coming up.
 
Yea, I understand you are still referencing the Inheritance tree diagram
which I think may be wrong for the following reasons primarily there is not
other documentation that explicitly states the MasterPage is derived from
UserControl --but-- there is explicit language that states the MasterPage
class is derived from the Page class which is what TemplateControl does.

[1] Remarks Par. 3:
The resulting compiled, merged class (MasterPage) derives from the Page
class.

[1] Remarks Par. 8:
The master page is made available to the content page through the Master
property of the base Page class.

[2] TemplateControl Class
Provides the Page class and the UserControl class with a base set of
functionality.

Q: Why does the MasterPage have to inherit the Page class when the
TemplateControl class provides the functionality to the MasterPage class as
the documentation explains in writing in several locations?

Q: Why does the documentation for TemplateControl not also mention the
MasterPage class which also derives its functionality from the Page class?

My argument has been there is what we call an "error and omission" and in
the real world there is actually insurance that can be purchased to pay for
the results of these types of errors and omissions when an architect is
simply following the documentation as it is expressed IN WRITING --not-- a
DIAGRAM as the Inheritance tree diagram would be defined in a court of law
where these matters would have to be resolved when the architect misplaces
his or her trust in an assumed trustworthy source only to discover at some
point in time after somebody has the roof fall on their head that there was
in fact an error and omission due to perhaps laziness or some other
generally understood observation of documentation that is contradictory.

The assertion here is basic and fundamental: there is no reason the
MasterPage needs to inherit the User Control to inherit the Page class when
the TemplateControl class makes the Page class available directly.

This is what I mean by strict constructionist. The documentation is either
trustworthy prima facie or it is not trustworthy. As I have shown three
contradictions of proof it must be concluded the documentation --is not
trustworthy prima facie-- which the authors have an obligation to clarify.

It is entirely possible and error has been made since there is clearly
documentation that contradicts the Inheritance tree diagram implying the
diagram itself may be incorrect and its the diagram and only the diagram
that most of you have relied on yet I have shown three proofs that
contradict the diagram. Its entirely possible the persons writing these
documentation pages simply did not know or did not care to use the correct
statement for the tree control used to generate that specific Inheritance
tree diagram is it not? This is my assertion.

Finally, I am no wizard at using reflection but given the time it would be
useful to fire up Roeder's tool and read the IL which I continue to think
will show no sign of the User Control class when a master page is being
compiled.


[1] http://msdn.microsoft.com/en-us/library/system.web.ui.masterpage.aspx
[2]
http://msdn.microsoft.com/en-us/library/system.web.ui.templatecontrol.aspx
 
Glad I can bring a healthy discussion to the table. You guys are obviously
experts and are way over my head. I went with what Mark said and used
iFrames.
 
iFrames are ca-ca and you will regret using iFrames. Google iFrames using
different terms for the words good and bad and then make up your mind...

What you asked about is simple. Just give the directions I suggested on
11/28 a try or you'll never get the hang of this if you can't do something
as simple as follow directions and click as instructed. I'll keep walking
you through if you need more help...
 
Hillbilly - I'm willing to take a stab at this if you're willing to help.
Please note I'm still a newbie at this. I'm doing all this in vb.net.

- The reason why I'm thinking I had to use iFrames is:
Every night, a 3rd party software generates a plain old .htm file. So this
file deletes and creates a new .htm file every night. From reading the
discussion you guys had, I've come to the conclusion that a Content Page is
actually the main page and the Master Page is just like a wrapper that wraps
around the Content page. I know I'm not talking in official programmers
languauge, but I'm a newbie so I have to talk about it in simple form so I
can understand. So, if a 3rd party program is creating this htm file every
night, it does not know that it's going to be a part of the MasterPage so it
can never be a Content Page, right? Then I'm stuck with iFrame, right?

-If I'm wrong, how can a simple plain htm from a 3rd party software load in
a Content Page?

Thanks!
Phil
 
Basically right but I need some preliminary information. For example answer
the following yes or no questions...

Q. Do you have any control of the .htm file at all?

Q. Is it possible to have the 3rd party software program save the file
without the following tags sets: <html>, <head>, <title>, and <body>?

Q. Is it possible to have the file saved to a different file extenstion:
..inc or .asp?

Q. Do you know what an HTML include directive is?

Q. Do you know what an ASP.NET User Control is yet?

Q. Did you ever do any mechanical or architectural drafting in school, for a
hobby or for employment?
 
Hillbilly said:
Basically right but I need some preliminary information. For example
answer the following yes or no questions...

Q. Do you have any control of the .htm file at all? NO

Q. Is it possible to have the 3rd party software program save the file
without the following tags sets: <html>, <head>, <title>, and <body>? NO

Q. Is it possible to have the file saved to a different file extenstion:
.inc or .asp? NO

Q. Do you know what an HTML include directive is? NO

Q. Do you know what an ASP.NET User Control is yet? YES

Q. Did you ever do any mechanical or architectural drafting in school, for
a hobby or for employment?
NO. I was an accounting major and I'm currently the CFO and help run a
$100mn mutual fund company. Programming is my hobby and not my profession
and it can never be. Just because it can never be my profession does not
mean I don't want to learn more about my hobby.

SO - Am I right to think I need to stick with iFrame since I have no control
of the output from this other software? It's always going to generate an
htm file. I know I can probably write some kind of program that will break
the file down, but it may not be worth it since it's repeated everynight and
the htm is fine the way it is. It's just not built for Mastpage scenerio.
 
Hello Christophe.
Is a dog also a human being because we both have legs or are we both a type
of mammal?

Don't confuse the regular use of a term (in this case "is a") with
it's technical uses in particular contexts.

If dog, mammal and humanBeing are OO classes, then

In OO terms, a dog "is a" mammal, and a humanBeing "is a" mammal.

This is pretty standard terminology, i.e.:

type A "is a" "type B" means "type A is the same as type B or type A
is a sub class of type B".

MasterPage subclasses UserControl, and so a MasterPage "is a"
UserControl.
 
I am formally educated, degreed and an experienced architect. On the basis
of my training if I were to make decisions on what is mearly implied as you
all have done in this matter by continually referring to nothing more than
the a listed item in an inheritance tree people could lose their lives.

Therefore I have been compelled to become a strict constructionist. Other
than the fact that the MasterPage and the User Control both inherit from the
Template Control Class I have yet to read one word of official documentation
that explicitly states the MasterPage --is a-- User Control. Furthermore,
there is so much documentation stating otherwise not to mention how
different each is in usage that I have been surprised people continue to
insist on claiming --is a-- rather then the more correct --type of--
description.

http://msdn.microsoft.com/en-us/library/system.web.ui.masterpage.aspx

which has:

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level =
AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class MasterPage : UserControl
 
Okay, I asked about drafting knowledge as it provides a perfect explanation
for how to understand MasterPages which was conceptually copied from overlay
drafting techniques and procedures used to build documents from templates.

Sure, you can use iFrames if you want as it is an easy way out but they can
and will impose gotchas here and there; unintended consequences. Try to work
with this code [1] as it is a better approach in the long run. The code will
strip out the parts of the HTML file that cannot be reused in a Content Page
which is why I asked other questions.

[1] http://www.mikesdotnetting.com/Article.aspx?ArticleID=33
 
This article [1] is helpful for us if as you suggest we attempt to classify
dogs and human beings using OOP as a means to manifest the classification.
Try to explain to me how we cab subclass dogs and human beings as we are
from different species ;-)

But I've now come to terms with the fact that MasterPage is a UserControl.


[1] http://en.wikipedia.org/wiki/Species
 
Back
Top