|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
controls & SessionHi
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 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 Peter Kirk wrote: Show quoteHide quote > 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 > > 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 Show quoteHide quote "mnichols" <mnicholscwi_nospam@yahoo.ca> skrev i en meddelelse news:eBnK68HwGHA.3364@TK2MSFTNGP02.phx.gbl... > 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 > > Peter Kirk wrote: >> 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 ASP.NET 2.x (and 1.x) have numerous caching options. These might help:
http://msdn2.microsoft.com/en-us/library/h30h475z.aspx http://msdn2.microsoft.com/en-us/library/726btaeh.aspx Peter Kirk wrote: Show quoteHide quote > 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 > > "mnichols" <mnicholscwi_nospam@yahoo.ca> skrev i en meddelelse > news:eBnK68HwGHA.3364@TK2MSFTNGP02.phx.gbl... >> 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 >> >> Peter Kirk wrote: >>> 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 > >
Asp.net charting control
Localization of the ASP.NET login control Drop Down Box Validation Problem usercontrols and postback Need Help with Control Selection remove border around checkboxes Calendar control - disabling past dates. What happen to powerupasp.net? Inserting using Formview Turn off ASP.NET 1.1 validators via client-side javascript |
|||||||||||||||||||||||