views:

101

answers:

3

I have a asp .net master page application and one content page has a number of controls on it.

I want to store the content/state of those controls in the session state whenever a user navigates to another content page.

My question is, how do I know when to capture the control state? Is there an event of some type I can use to trigger a procedure?

Thanks in advance for any info.

Bill

A: 

Presumably they are navigating away from that page via a control that you have provided them (button, link, etc.) You can trap the action on the server side at that point and cache your state.

JP Alioto
+1  A: 

There aren't any real "global" server side event handlers that you can use to detect when the user is going to another page (or even just hitting the back button in the browser).

The best bet is to simply write a method in your master page that will save your session state and then execute a Response.Redirect() to the location specified. Then make all of your links go through this method when you need to track session state.

Dillie-O
A: 

What about using session variables?

See this link for more info: http://stackoverflow.com/questions/133236/asp-net-session

There's a number of ways to maintain state. There are trade-offs no matter which version you use. For example, I wouldn't use session variables on an app that is load-balanced across multiple servers; you're not guaranteed to get the same server for each request, and the state is stored on a server-by-server basis.

It's hard to beat this

Session["myState"] = 7;  // bad example

for simplicity, though. :)

Jeramy Rutley