views:

246

answers:

1

I've defined a helper class to keep track of a small dictionary of items. it stores this information as a static property, which is initialized in the static constructor. the list is very small and will never change so I chose this method over xml or a db lookup table...

however what I would like to know is, will this static property retain its values between pages, or even within pages if asp.net is supposed to be stateless?

for example, I'm binding this list to two different dropdownlists on my page

DropDownList1.DataSource = Helper.MyList;
DropDownList2.DataSource = Helper.MyList;

Since the static class Helper is called two separate times, is its constructor also called twice, or does it stay in scope throughout the full page lifecycle?

What about if I navigate to the next page and need to bind again, will it still be initialized or will it start all over again?

+2  A: 

No, that won't initialize the type twice. The Helper class will only need to be reinitialized next time you get a new AppDomain - either because the application is refreshed/restarted or due to AppDomain recycling.

Jon Skeet