• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 813
  • Last Modified:

page_load and constructor

What's wrong with the following? Does page_load by default call a constructor implicitly? Where is the constructor of the class?

private page_load (...)
{
  new Constructor();
}

public Constructor()
{
   .......
}


Thanks.


0
samliam
Asked:
samliam
  • 2
1 Solution
 
brabchevCommented:
What do you mean?
Be more specific and post a whole class.
0
 
purpleblobCommented:
I'm making assumptions here such as you've removed the class declaration and returntypes etc., but assuming these things. What appears to be happening is that page_load is a method which instantiates a class called Constructor, it doesn't keep a reference to the instance so I would assume everything is mean't to happen would happen in the class Constructor's constructor. Now Assuming that your second declaration is mean't to be a class (but no class keyword is shown so this is an assumption) and also assuming you've not supplied a constructor what happens is that a default one is supplied for you implicitly.

Obviously these assumption would mean that as you're not deriving from a base class which supplies a default constructor that in fact all that will happen in this code is it'll create an instance of Constructor then throw the instance away until it's garbage collected.

Not sure if this helps, feel free to clarify if you need further info.
0
 
ptmcompCommented:
Page_Load is an event handler. When it's called the page object is already created.
There is a request handler that constructs the page object this is outside of the Page class.

You can find more information here: http://www.15seconds.com/issue/020102.htm
0
 
ptmcompCommented:
public Constructor() - this looks like a mixing up object pascal with C#. A contructor has always the name of the class:

class MyClass
{
    // constructor
    public MyClass()
    {
    }
}
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now