P
Pavils Jurjans
Hello,
I am now digging through ASP.NET, so please forgive me if I ask some
common-sense questions, as I come with long-years classic ASP background.
I was just playing with code-behind features, and found out some shocking
(at least for me) news.
This is the aspx file:
<%@ Page Language="C#" inherits="CBTest"%>
<%=counter++%>
This is the code for code-behind class:
public class CBTest : System.Web.UI.Page
{
public static int counter;
}
Now, I go to the browser, and type the local URL to see that page, and get,
of course "0", now, if I keep clicking "Refresh" button, I see the counter
growing. What is going on here? Is the static property of Page type class
persistent over requests? I tried to turn off session state, but the
behaviour is still the same. How that actually works? I did some testing to
find out that not only static properties of Page type objects, but even
self-sustained custom-made class static properties where keeping their
values over consequent requests to the same page.
I am quite surprized on this. I expected that I still have to use Session
object to keep values over requests. I have read the new paradigm of
persistent control states, but I really didn't expect that simple static
properties of any class present in my application would keep their values.
Please, someone, clear up for me what's going inside here!
Thanks,
-- Pavils
I am now digging through ASP.NET, so please forgive me if I ask some
common-sense questions, as I come with long-years classic ASP background.
I was just playing with code-behind features, and found out some shocking
(at least for me) news.
This is the aspx file:
<%@ Page Language="C#" inherits="CBTest"%>
<%=counter++%>
This is the code for code-behind class:
public class CBTest : System.Web.UI.Page
{
public static int counter;
}
Now, I go to the browser, and type the local URL to see that page, and get,
of course "0", now, if I keep clicking "Refresh" button, I see the counter
growing. What is going on here? Is the static property of Page type class
persistent over requests? I tried to turn off session state, but the
behaviour is still the same. How that actually works? I did some testing to
find out that not only static properties of Page type objects, but even
self-sustained custom-made class static properties where keeping their
values over consequent requests to the same page.
I am quite surprized on this. I expected that I still have to use Session
object to keep values over requests. I have read the new paradigm of
persistent control states, but I really didn't expect that simple static
properties of any class present in my application would keep their values.
Please, someone, clear up for me what's going inside here!
Thanks,
-- Pavils