Back to "Very small tip...ViewState enabled properties"

This is a viewer only at the moment see the article on how this works.

To update the preview hit Ctrl-Alt-R (or ⌘-Alt-R on Mac) or Enter to refresh. The Save icon lets you save the markdown file to disk

This is a preview from the server running through my markdig pipeline

ASP.NET C# Imported mostlylucidcouk Web Development

Very small tip...ViewState enabled properties

Friday, 19 March 2004

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...

logo

© 2025 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.