Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

When inheriting from System.Web.UI.Page or UserControl, do I have to     call their contructors?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DotNetNewbie - 29 Feb 2008 12:46 GMT
Hi,

When inheriting from System.Web.UI.Page (or any other class for that
matter), do I have to call the inherited classes constructors?

I've seen allot of code where people do:

protected override void OnInit(EventArgs e)
{
           base.OnInit(e);
}

Is this necessary if we don't override any methods/events of the
inherited class also?
Jon Skeet [C# MVP] - 29 Feb 2008 12:56 GMT
> When inheriting from System.Web.UI.Page (or any other class for that
> matter), do I have to call the inherited classes constructors?
[quoted text clipped - 5 lines]
>             base.OnInit(e);
>  }

That's probably just created by the designer. It's not doing anything
useful.

Note that that *isn't* calling the constructor - it's calling the
OnInit method.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Nicholas Paldino [.NET/C# MVP] - 29 Feb 2008 15:50 GMT
The OnInit is useful.  If it isn't called, then themes and stylesheets
generated in code or through ASP.NET control markup will not be applied.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>> When inheriting from System.Web.UI.Page (or any other class for that
>> matter), do I have to call the inherited classes constructors?
[quoted text clipped - 11 lines]
> Note that that *isn't* calling the constructor - it's calling the
> OnInit method.
Jon Skeet [C# MVP] - 29 Feb 2008 15:56 GMT
>     The OnInit is useful.  If it isn't called, then themes and stylesheets
> generated in code or through ASP.NET control markup will not be applied.

But surely overriding OnInit to just call base.OnInit isn't useful is
it? How can that change anything?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Nicholas Paldino [.NET/C# MVP] - 29 Feb 2008 17:26 GMT
I thought you were referring to just the call to OnInit in the override.
The assumption was that there was some other code after the call to OnInit.
If that's all there is in the method definition, then yes, it's pretty
pointless.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>>     The OnInit is useful.  If it isn't called, then themes and
>> stylesheets
>> generated in code or through ASP.NET control markup will not be applied.
>
> But surely overriding OnInit to just call base.OnInit isn't useful is
> it? How can that change anything?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.