Showing posts with label state management. Show all posts
Showing posts with label state management. Show all posts

Tuesday, June 16, 2009

IPostBackHandler and EnableViewState

I've spent several hours troubleshooting a crazy bug, which is explained in detail here. In a nutshell, the changed state of toolbar buttons (ASP.Net LinkButton controls) was not being kept. Every time a partial postback occurred on the web page, the changes would disappear.

I did much research and learned that the IPostBackHandler mechanism is what was responsible for restoring the control values after each postback. For some reason it didn't appear to be working. I even built a small test project but it did work in that!

Suddenly I noticed that the test page in my main project had EnableViewState=false. I changed it to true and ... everything worked fine!

My findings seem to conflict with several articles, including this one. All I know is that in my case EnableViewState must be set to true.

I'm posting this, both as a future reminder to myself and in the hopes that a State Management guru will read it and explain to me what's really going on.

Wednesday, November 19, 2008

Better Understanding of State Management in ASP.Net

For some time I've been using all of these special ASP.Net objects to assist with state management:
  • Cache
  • Application
  • Session
Up until now though, I was misinformed about something. I had thought that when I retrieved a complex object out of one of these state management objects that I was getting a copy of it. In this way, I could do some work on the "temporary object" but then had to save it back in order for the change to be permanent.

This is absolutely incorrect!

So, for example:

DataTable dtEmployees = (DataTable)Session["Employees"];
DataRow row = dtEmployees.Rows[5];
row["FirstName"] = "Steve";

I do NOT have to use the following line:

Session["Employees"] = dtEmployees;


Rather, right after the name was changed above, I could have done this:

((DataTable)Session["Employees"]).Rows[5]["FirstName"]

and "Steve" would be returned!