controls & Session

P

Peter Kirk

Hi

does a control know when it is no longer being shown?

What I mean is that I have several controls (ascx) which use the Session to
store data. The controls are not on the same page (aspx) but use some of the
same "names" for data in the Session - and this can cause conflicts between
the controls.

What I would like to do is to remove data from the Session when a control is
no longer on the page being shown - does a control have a
"no-longer-on-the-displayed-page" method/event which I can override and add
code to remove data from the Session?


Thanks,
Peter
 
M

mnichols

Some ideas:
- Unlike Windows forms, Web forms are stateless, the server has no idea when a page is closed, if it will be refreshed or posted back.
- ASP.NET pages have a ViewState, you can use that to store data in. The ViewState basically stores the information in the web page itself so that if it is posted back then the data can be reused. This is not recommended for large amounts of data.
- You can use more creative session variables names that indicate which page they are storing data for but that will probably only introduce different problems and bog down your session/server.
- Generally web pages have to recreate their datasets each time a page is written out however you can store data in the session cache with a reasonable timeout period and then recreate the data only when necessary. This might be the most efficient
approach for what you need.

HTH

mnichols
 
P

Peter Kirk

Hi

thanks for the quick response and ideas.

There is a relatively large amount of data - it is for a sorting and paging
functionality of some data, so I did not want to use ViewState.

I had thought about simply ensuring that each control uses some "custom" and
unique naming convention for Session data - I had just hoped I would not
have to resort to changing the controls' code, as they are "working
components" which I didn't really want to touch. But I can see that in the
long run using some sort of unique naming convention for global things like
the Session is probably a good idea.

Thanks,
Peter
 

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

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top