Loading webcontrols problem

T

ThunderMusic

Hi,
I always refer to this page to know the order of events in a page :
http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx but this time,
I'm mystified...

I have a Control called "ImagePreloader" I placed in the head of my
MasterPage (aspx)... in the Init of the "ImagePreloader", I put the
instance in the HTTPContext.Current.Cache... and provide a static method so
other controls can have access to the ImagePreloader... On a P IV 3Ghz,
WinXP Pro SP2, IIS 5, everything works fine... On a P III 1Ghz, WinXP Pro
SP2, IIS 5, It sometimes happen that when other controls want to get the
instance in their PreRender events (so way after the OnInit), the instance
has never been created... If I put a breakpoint in the OnInit of the
ImagePreloader, it never gets there even tought it's a control in the aspx
of the masterpage... Maybe it's not related to speed at all, but I really
don't know what can cause this...

can anyone help me please?

Thanks

ThunderMusic
 
G

Guest

Hi there,

I think entitre logic yore are based on is wrong. What do you mean by 'I put
the instance in the HTTPContext.Current.Cache'? Could you provide some code
to show us what are you doing? I suspect you put an instance to cache, and
this instance is reused in every request (which is not acceptable because
different threads work on the same control ?!) did i get you right?
 
T

ThunderMusic

Hi,
I think you didn't get me right, but maybe it's me that didn't get the thing
right... I put the instance in the HTTPContext so all requests (from other
controls on the page) from this request (this user request to the page) have
an instance to work with... I want it to work as a singleton, but for one
webrequest only... just like the ScriptManager of ASP.NET Ajax (which I
don't use)... I think I've done it tought... I finally found the problem
was reproduced everytime I hit the reload button, so I looked at what was
called after that and surprisingly, everything is called, but the instance
does not stay in cache after the constructor, neither after the OnInit
event, but it does after the OnLoad event (go figure), so I put it there,
because my controls use it in the PreRender anyway... ;)

I use exactly this line in the constructor and the OnLoad of the
ImagePreloader WebControl :
HttpContext.Current.Cache["ImagePreloader"] = this;

Thanks to all, and I hope I helped others if they need this kind of
behavior...

ThunderMusic
 
T

ThunderMusic

ok, I said it too quick... it does not always work... It crashes regularly
on Netscape... and it goes in the constructor, it goes in the OnLoad, then
when my controls request for it in their OnPreRender, it says it does not
exist... Anyone have an idea of what could be the cause? what is the use
of putting something the the Context cache if it does not stay there? Where
should I put it then?

Thanks

ThunderMusic


ThunderMusic said:
Hi,
I think you didn't get me right, but maybe it's me that didn't get the
thing right... I put the instance in the HTTPContext so all requests
(from other controls on the page) from this request (this user request to
the page) have an instance to work with... I want it to work as a
singleton, but for one webrequest only... just like the ScriptManager of
ASP.NET Ajax (which I don't use)... I think I've done it tought... I
finally found the problem was reproduced everytime I hit the reload
button, so I looked at what was called after that and surprisingly,
everything is called, but the instance does not stay in cache after the
constructor, neither after the OnInit event, but it does after the OnLoad
event (go figure), so I put it there, because my controls use it in the
PreRender anyway... ;)

I use exactly this line in the constructor and the OnLoad of the
ImagePreloader WebControl :
HttpContext.Current.Cache["ImagePreloader"] = this;

Thanks to all, and I hope I helped others if they need this kind of
behavior...

ThunderMusic

Milosz Skalecki said:
Hi there,

I think entitre logic yore are based on is wrong. What do you mean by 'I
put
the instance in the HTTPContext.Current.Cache'? Could you provide some
code
to show us what are you doing? I suspect you put an instance to cache,
and
this instance is reused in every request (which is not acceptable because
different threads work on the same control ?!) did i get you right?
 
G

Guest

Hi again

I'm afraid i got you right.
HttpContext.Current.Cache["ImagePreloader"] = this;
Adds instance to cache and will be used in many request threads so don't
expect it's gonna work. I think you misused cache with context items - it
should have been:
HttpContext.Current.Items["ImagePreloader"].

In addtion to that there is better way to access current request execution
Context from web user control:

this.Context.Items["ImagePreloader"]

or from web custom control:

this.Context.Items["ImagePreloader"]

Hope it's clear now.
--
Milosz


ThunderMusic said:
Hi,
I think you didn't get me right, but maybe it's me that didn't get the thing
right... I put the instance in the HTTPContext so all requests (from other
controls on the page) from this request (this user request to the page) have
an instance to work with... I want it to work as a singleton, but for one
webrequest only... just like the ScriptManager of ASP.NET Ajax (which I
don't use)... I think I've done it tought... I finally found the problem
was reproduced everytime I hit the reload button, so I looked at what was
called after that and surprisingly, everything is called, but the instance
does not stay in cache after the constructor, neither after the OnInit
event, but it does after the OnLoad event (go figure), so I put it there,
because my controls use it in the PreRender anyway... ;)

I use exactly this line in the constructor and the OnLoad of the
ImagePreloader WebControl :
HttpContext.Current.Cache["ImagePreloader"] = this;

Thanks to all, and I hope I helped others if they need this kind of
behavior...

ThunderMusic

Milosz Skalecki said:
Hi there,

I think entitre logic yore are based on is wrong. What do you mean by 'I
put
the instance in the HTTPContext.Current.Cache'? Could you provide some
code
to show us what are you doing? I suspect you put an instance to cache, and
this instance is reused in every request (which is not acceptable because
different threads work on the same control ?!) did i get you right?
 
T

ThunderMusic

thanks a lot, I'll try this... I knew I was missing something... thanks
I'll let you know if it works...


Milosz Skalecki said:
Hi again

I'm afraid i got you right.
HttpContext.Current.Cache["ImagePreloader"] = this;
Adds instance to cache and will be used in many request threads so don't
expect it's gonna work. I think you misused cache with context items - it
should have been:
HttpContext.Current.Items["ImagePreloader"].

In addtion to that there is better way to access current request execution
Context from web user control:

this.Context.Items["ImagePreloader"]

or from web custom control:

this.Context.Items["ImagePreloader"]

Hope it's clear now.
--
Milosz


ThunderMusic said:
Hi,
I think you didn't get me right, but maybe it's me that didn't get the
thing
right... I put the instance in the HTTPContext so all requests (from
other
controls on the page) from this request (this user request to the page)
have
an instance to work with... I want it to work as a singleton, but for one
webrequest only... just like the ScriptManager of ASP.NET Ajax (which I
don't use)... I think I've done it tought... I finally found the
problem
was reproduced everytime I hit the reload button, so I looked at what was
called after that and surprisingly, everything is called, but the
instance
does not stay in cache after the constructor, neither after the OnInit
event, but it does after the OnLoad event (go figure), so I put it there,
because my controls use it in the PreRender anyway... ;)

I use exactly this line in the constructor and the OnLoad of the
ImagePreloader WebControl :
HttpContext.Current.Cache["ImagePreloader"] = this;

Thanks to all, and I hope I helped others if they need this kind of
behavior...

ThunderMusic

Milosz Skalecki said:
Hi there,

I think entitre logic yore are based on is wrong. What do you mean by
'I
put
the instance in the HTTPContext.Current.Cache'? Could you provide some
code
to show us what are you doing? I suspect you put an instance to cache,
and
this instance is reused in every request (which is not acceptable
because
different threads work on the same control ?!) did i get you right?
--
Milosz


:

Hi,
I always refer to this page to know the order of events in a page :
http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx but this
time,
I'm mystified...

I have a Control called "ImagePreloader" I placed in the head of my
MasterPage (aspx)... in the Init of the "ImagePreloader", I put the
instance in the HTTPContext.Current.Cache... and provide a static
method
so
other controls can have access to the ImagePreloader... On a P IV
3Ghz,
WinXP Pro SP2, IIS 5, everything works fine... On a P III 1Ghz, WinXP
Pro
SP2, IIS 5, It sometimes happen that when other controls want to get
the
instance in their PreRender events (so way after the OnInit), the
instance
has never been created... If I put a breakpoint in the OnInit of the
ImagePreloader, it never gets there even tought it's a control in the
aspx
of the masterpage... Maybe it's not related to speed at all, but I
really
don't know what can cause this...

can anyone help me please?

Thanks

ThunderMusic
 

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,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top