 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

August 2nd, 2010, 03:23 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Page 210:Page object calling a private method from BasePage?
Note "Private Sub Page_PreRender" is a private method. How does the derived Page Class manage to call this private method? BTW the book is excellent and crammed with info.
|
|

August 2nd, 2010, 03:26 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
How does the derived Page Class manage to call this private method?
|
It doesn't. It's the BasePage class itself that executes this code. Or in fact, it's the parent Page class that raises the event which is then handled by BasePage.
Quote:
|
BTW the book is excellent and crammed with info.
|
Thank you. Spread the word, Spread the word.... ;-)
Cheers,
Imar
|
|

August 2nd, 2010, 03:45 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Imaar,
Thanks for the reply.
Do you mean when (say) Default.aspx object is created, it's constructor calls the base page's constructor, which raises the Page.PreRender event and so the the code is executed?
You don't put this code in the master page because masterpage is suited to handle common layout but BasePage is suited to handle common programming logic?
If you have a bit of time, can you tell me how to best understand inheritance? As when you call an inherited method MethodA() in the derived class, does it actually creates a base class object and pass the call to the base class's MethodA()? So even private methods are inherited becasue the derived object just pass the call to the base class method?
I'm gonna write good reviews on Amazon after I finish reading the whole book. Cheers.
|
|

August 2nd, 2010, 04:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Quote:
|
Do you mean when (say) Default.aspx object is created, it's constructor calls the base page's constructor, which raises the Page.PreRender event and so the the code is executed?
|
The other way around. When the child class is created, first the base constructor is called, then its own. You may want to read more about this here:
http://www.codeproject.com/KB/dotnet...sInCSharp.aspx
http://www.blackwasp.co.uk/ConstructorInheritance.aspx
http://aspalliance.com/770
http://www.yoda.arachsys.com/csharp/constructors.html
http://blogs.msdn.com/b/ericlippert/...-part-one.aspx
http://blogs.msdn.com/b/ericlippert/...-part-two.aspx
Quote:
|
You don't put this code in the master page because masterpage is suited to handle common layout but BasePage is suited to handle common programming logic?
|
TYes, that's how I typically handle it. You can mix and match if you want, but I find that separating logic and design like this makes a lot of sense.
Quote:
|
As when you call an inherited method MethodA() in the derived class, does it actually creates a base class object and pass the call to the base class's MethodA()? So even private methods are inherited becasue the derived object just pass the call to the base class method?
|
Not, not really. it doesn't create the base class, it *is* the base class, plus more. Think animals, for example. A dog is an animal, so when you create a dog you actually create an animal of type dog. The dog itself doesn't create an animal, it *is* an animal.
So, when you have this:
public class Dog : Animal {... }
and then construct a dog like this:
Dog myDog = new Dog();
Then first the Animal's constructor is called.
To see what I mean, put breakpoints in your code such as in the BasePage class and then debug (see Chapter 18). Then you can see the order of events.
Cheers,
Imar
|
|

August 8th, 2010, 10:20 PM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
|
|
Wow, some pretty heavy stuff, and an hour before I retire for the night. I was searching chapter 6 threads for more info and was glad to read it. I had just written in the book margins to go over the pages 210-214. I do understand much of this better, but I think that as I am reading ahead a bit to use the Master pages, to learn the design techniques for a template.
I think it is a great lesson in Base Pages and Inheritance. I think writing some classes while I am learning the basics of ASP.NET will help. I am thinking of putting up a couple of metric to English pages on my website, since I am on a Dieting forum with people in Australia, England, Europe and Canada and we are weighing in kilograms and pounds. I'm always telling the temperature in Michigan in Fahrenheit and then converting it longhand on paper to Celsius, so I am going to add this to my website at www.bdtcomp.com and maybe at the same time make a master page of my current design which is a combination of PHP and CSS. So in effect I'm killing two birds with one stone. (bad analogy because I love my animals, because we have a yellow lab and two yellow cats.)
The importance of this base page, so far is a great way to force you to put titles on all your web pages, something that I forget to do too often! 
Last edited by btcomp; August 8th, 2010 at 11:03 PM..
|
|

August 9th, 2010, 02:25 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
The importance of this base page, so far is a great way to force you to put titles on all your web pages,
|
Yes, but that's only one of its uses....
Imar
|
|

August 9th, 2010, 07:04 AM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
|
|
I agree, it's my starting point with the base page. I've bookmarked this link to look at as I learn more. http://www.codeguru.com/csharp/.net/...cle.php/c11939
|
|
 |
|