I personally like option one below for maintainability but I could see option two getting me better performance. Option three is probably complete garbage.
1. ViewState["Calendar1.SelectionMode"] = Calendar1.SelectionMode;
2. ViewState["CSM"] = Calendar1.SelectionMode;
3. ViewState["Calendar1_SelectionMode"] = Calendar1.SelectionMode;
Am I applying old school habits of thinking about the maintenance? Does it matter only when the number of objects is large? I cannot see the internals using anything but a very efficient hash. I have read up on methods to speed up the page loading but nothing directly advising as this being even a slight factor. All the literature talks about is prefering the viewstate over database access reads, using compact types, populating only those values that take on non default values.
Option two will probably give you better performance, but the difference is extremely small. If you're experiencing performance problems this would be one of the very last places I would look for bottlenecks. Have you run any kind of profiling on your page? That's where I would start looking.
The key names become part of the viewstate hidden field. Crude example:
protected void Page_Load(object sender, EventArgs e)
{
// ViewState["a"] = 1;
// <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
// value="/wEPDwUJNzgzNDMwNTMzDxYCHgFhAgFkZCdtAzza2+uuoGpYdGLBUdCkUGe7" />
// ViewState["this is a very very very very long key"] = 1;
// <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
// value="/wEPDwUJNzgzNDMwNTMzDxYCHiZ0aGlzIGlzIGEgdmVyeSB2ZXJ5IHZlcnkgdmVyeSBsb25nIGtleQIBZGSmj9cou408+XXRLxCLKcEoLngriA==" />
}
Bottom line: unless you are storing a large number of keys, likely not an issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With