Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
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
 
Old August 2nd, 2010, 03:23 AM
Registered User
 
Join Date: Aug 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old August 2nd, 2010, 03:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 2nd, 2010, 03:45 AM
Registered User
 
Join Date: Aug 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old August 2nd, 2010, 04:03 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 8th, 2010, 10:20 PM
Authorized User
 
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

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!
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill

Last edited by btcomp; August 8th, 2010 at 11:03 PM..
 
Old August 9th, 2010, 02:25 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 9th, 2010, 07:04 AM
Authorized User
 
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

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
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill





Similar Threads
Thread Thread Starter Forum Replies Last Post
Page 210 Try it out. flapjack BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 May 1st, 2010 03:23 AM
Master Page Method: Code-Behind for Content Page kwilliams ASP.NET 2.0 Professional 3 June 2nd, 2008 12:57 PM
posting an object from one page to other page g_vamsi_krish ASP.NET 1.0 and 1.1 Basics 10 March 16th, 2006 01:57 AM
calling private method from another class jack_3 C# 3 December 16th, 2005 07:56 PM
Calling second page from 1st page shoakat Classic ASP Databases 4 September 30th, 2004 04:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.