Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 134991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:42:47+00:00 2026-05-11T06:42:47+00:00

A question I have been thinking about for a while – would Stackoverflow users

  • 0

A question I have been thinking about for a while – would Stackoverflow users commonly implement significant functionality in a constructor (specifically in classes derived from the System.Web.UI.Page class) , or should we keep the logic here as simple as possible and instead implement functionality in OnPreInit (using the constructor to simply instantiate objects/values that are required for the functionality in the rest of the page to function)? Is there a ‘best-practice’ approach to this scenario?

The background to this question:

The system that I am working on has a fairly deep page hierarchy – there are about 10 chained page objects that the actual page derives from:

  -- System.Web.UI.Page  ----- CustomPage1 : System.Web.UI.Page  -------- CustomPage2 : CustomPage1 ---------- etc  

Each page adds a specific piece of functionality, and often there is either a dependancy on code run within the custom page constructor, or the functionality itself is directly run during construction.

The example that best illustrates my question is the page that loads custom objects from our database to the page so they are available during the page lifecycle – during page construction connections are made to the database and then public properties are populated with the correct values.

To my mind this is better done from the OnPreInit event, mainly because we have greater flexibility to perform some page level checks (e.g. should we want to prevent this functionality being called) before the parent logic is run (given that in a constructor the order of execution will construct the parent classes before the child class). From an OO perspective as well OnPreInit seems to be a more appropriate area to implement this functionality – page construction should deal with construction of the page, setting any default values, etc and then OnPreInit would be used to perform any functionality that was required during the lifecycle of the page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:42:48+00:00Added an answer on May 11, 2026 at 6:42 am

    I think your reasoning is very sound – I agree that OnPreInit is the proper place for such logic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer $('#tableofdata tr td:nth-child(3)') or simply: $('#tableofdata tr td:last-child') To grab… May 11, 2026 at 11:40 am
  • added an answer It makes more sense to ask about a particular aspect… May 11, 2026 at 11:39 am
  • added an answer Seems that you have some typos, JS is case sensitive,… May 11, 2026 at 11:39 am

Related Questions

Ok, have a bunch of questions that I have been thinking about the past
I've been thinking about software estimation lately, and I have a bunch of questions
There is a question I have been wondering about for ages and I was
This is a (hopefully) really simple question - I have been told recently that
This might be too opinionated a question, but looking for help! I have been
This may be a bit of a nooby question, I have been trying to
I have been asking myself this question for a long time now. Thought of
I've been watching Douglas Crockford's talks at YUI Theater, and I have a question
I've been hearing about triggers, and I have a few questions. What are triggers?
There have been a couple of questions that sort of dealt with this but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.