This really is a very quick tip...I think I got it from Fritz Onion'sexcellent Essential ASP.NET with Examples is C# (which I really recommend incidentally!). If you want to store a property which should persist using ViewState, you can save yourself a lot of typing and get (IMHO) cleaner code using this method:
public int Test{get{if(ViewState["Test"] != null)return (int)ViewState["Test"];elsereturn 0;}set{ViewState["Test"] = value;}}
So, there you go...short but hopefully useful - this is how I tend to work now...it also allows me to switch to session / cache persistence when necessary by just changing the little accessors...
© 2025 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.