Page Load order and Constructor

M

Mike P

Hi,

I have a problem which I'm sure lots of people must have seen so apologies
if this is well known!
Each of my aspx pages inherits from a base class which contains some
intitalization code for all pages. All ths user cotrols on the page use
these intialised fields however, placing them in the OnInit event of the
base page means they do not get run till last which means the user controls
do not see those initialized fields and so have empty object refrences. To
solve this I put the intialization code into the contructor for the base
page HOWEVER, this blows up the designer in Visual Studio as the
initialization code references objects that are only available at runtime
and when opening up the page in the designer, a horrible object not set to
reference occurs. Is there anyway to have my cake and eat it? Can I
initialize these fields in the base class, have them available in my user
controls but not have the designer blow up?

Any help wil be graetfully received

Cheers

Mike
 
B

bruce barker

the usual trick is to check if Response is null (indicates you are in
designer mode), but you can also override the OnInit method and initialize
there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top