Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Constructor not executing

Status
Not open for further replies.

flanakin

Programmer
Mar 21, 2000
158
US
In my web form, my page's constructor is not being executed. Does anyone have any idea why this would be happening? Any help is appreciated.

________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
May we see

(a)your page_load function (which I assume is what you refer to)

-and-

(b)your page_init and InitializeComponent methods?

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
By implication, since those are both protected/private methods, they cannot be executed until the constructor is run, so they would do no good. If you insist, I can show them, but it would not help any.

________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
Are you saying that you created a method with a return value the name of your page? Like....


Code:
public class MyPage : System.Web.UI.Page
{
    public MyPage(){
    
    //do something constructive here...
    
    }
   
}


Never tried that... Does it work? I usually use the Page_Load event to do initialization and other "construtor-like" operations.

What I HAVE done is create a base class that inherits from System.Web.UI.Page and have my pages inherit from it. The constructors in the base class will execute. Good for instantiating objects you want common to all pages.

 
That's what I'm doing...

public class Login : TemplatePage
{
public Login() : base("Login")
{}

...
}

And, for some reason, the constructor was not running. It's working, now, but I didn't change anything, so I'm even more clueless now than before.

________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
Theoretically you shouldn't have to call base() - it should execute by default. Part of the reason you might want it in a base class is that you don't have to ever think about it again - it'll "just happen" without having to be prodded.

BUT you are not using a parameter-less constructor? Hm... That could complicate things.

Regards,

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top