Callback method isn’t executed as part of web-request, even if declared in same class

F

frankswildyearstom

hello


Q1:
"ASP.NET also allows you to write a callback method that will be
triggered when an item is removed from the cache. You can place the
method that handles the callback in your web-page class, or you can
use a static method in another accessible class. However, you should
keep in mind that this code
won’t be executed as part of a web request. That means you can’t
interact with web-page objects or notify the user."

A) I don’t understand why, assuming callback method is declared in web-
page class, won’t this callback method be executed as part of a web
request. After all, if method is in same class, then it has access to
all the web-objects and thus should also be able to interact with
them?

B) Also, if item is removed in, say, Page_Load() then that method
will be called from Page_Load(), so how is it not executed as part of
a web request?




Q2:
A) If parent control has its view state disabled, then all of its
child controls automatically have their view states also disabled. Why
is that?

As far as I know, each control has its own Viewstate object - thus
it's not like child controls use the same Viewtate object as their
parent!



B) What is the reasoning (from design’s point of view) behind this?


much appreciated
 
G

GArlington

hello

Q1:
"ASP.NET also allows you to write a callback method that will be
triggered when an item is removed from the cache. You can place the
method that handles the callback in your web-page class, or you can
use a static method in another accessible class. However, you should
keep in mind that this code
won’t be executed as part of a web request. That means you can’t
interact with web-page objects or notify the user."
You should consider when the main action [item is removed from the
cache] is likely to occur?
It is NOT likely that it will coincide with web request...
A) I don’t understand why, assuming callback method is declared in web-
page class, won’t this callback method be executed as part of a web
request. After all, if method is in same class, then it has access to
all the web-objects and thus should also be able to interact with
them?

B) Also, if  item is removed in, say, Page_Load() then that method
will be called from Page_Load(), so how is it not executed as part of
a web request?

Q2:
A) If parent control has its view state disabled, then all of its
child controls automatically have their view states also disabled. Why
is that?
Again, it is logical... When the main element is disabled it is
logical to disable the child (related subset of data) to be disabled
too...
 
I

Ignacio Machin ( .NET/ C# MVP )

hello

Q1:
"ASP.NET also allows you to write a callback method that will be
triggered when an item is removed from the cache. You can place the
method that handles the callback in your web-page class, or you can
use a static method in another accessible class. However, you should
keep in mind that this code
won’t be executed as part of a web request. That means you can’t
interact with web-page objects or notify the user."

A) I don’t understand why, assuming callback method is declared in web-
page class, won’t this callback method be executed as part of a web
request. After all, if method is in same class, then it has access to
all the web-objects and thus should also be able to interact with
them?

Remember that this method can be called without a request being
processed. That;s why you should not expect that a request is in
progress.

B) Also, if  item is removed in, say, Page_Load() then that method
will be called from Page_Load(), so how is it not executed as part of
a web request?

But there is nothng that assure you it will, so you cannot assume it's
part of a request
 
I

Ignacio Machin ( .NET/ C# MVP )

hello

Q1:
"ASP.NET also allows you to write a callback method that will be
triggered when an item is removed from the cache. You can place the
method that handles the callback in your web-page class, or you can
use a static method in another accessible class. However, you should
keep in mind that this code
won’t be executed as part of a web request. That means you can’t
interact with web-page objects or notify the user."

A) I don’t understand why, assuming callback method is declared in web-
page class, won’t this callback method be executed as part of a web
request. After all, if method is in same class, then it has access to
all the web-objects and thus should also be able to interact with
them?

B) Also, if  item is removed in, say, Page_Load() then that method
will be called from Page_Load(), so how is it not executed as part of
a web request?

Q2:
A) If parent control has its view state disabled, then all of its
child controls automatically have their view states also disabled. Why
is that?

Not only the viewState, it also happen with the Visible property and I
bet with some other too


As far as I know, each control has its own Viewstate object - thus
it's not like child controls use the same Viewtate object as their
parent!

B) What is the reasoning (from design’s point of view) behind this?

I guess it has to do with the invoking sequence, It's a Top Down from
the page to its children controls, if one of the control has no
ViewState it does not go down further.
I would guess that the method looks something like:
void RestoreViewState(){
//restore my viewstate

foreach(Control c in Controls)
c.RestoreViewState();
}
 
F

frankswildyearstom

Hello,

Remember that this method can be called without a request being
processed. That;s why you should not expect that a request is in
progress.

On Mar 23, 11:07 pm, (e-mail address removed) wrote:> hello


You should consider when the main action [item is removed from the
cache] is likely to occur?
It is NOT likely that it will coincide with web request...

A) So this item removing logic (assuming this logic is defined inside
code-behind class ) can be called by code not defined in code-behind
class? What else can call this logic then? Custom HTTP handlers/HTTP
modules (don’t know anything about them) perhaps?

B) but still, I’d assume that item removing logic (and thus callback
method) can also be executed as part of a web request ( meaning
Page_Load() could call this logic ), even though this logic still
won’t be able to interact with web controls?

C) I assume logic for removing an item from the cache is usually (if
not always)defined in your code behind class?

But there is nothng that assure you it will, so you cannot assume it's
part of a request


A) But fact still remains that by C# rules any code defined inside
some class will have access to members of that class. Now even if item
removing logic is called from outside code-behind class, fact still
remains that this logic is still defined inside code-behind class and
thus should have same rights as other any code inside code-behind
class class – I’m not sure if I worded this properly

B) And following this reasoning we could also assume that any method
defined inside your code-behind could be called by outside code ( such
as HTTP handlers ) and thus those methods also shouldn’t interact with
web controls?
 

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

Top