Say I have 5 buttons on a page, numbered 1-5.
When one is clicked, a value with a viewtate getter/setter assigns this the value of the button clicked.
If I am checking for a value in Page_Init() / OnInit(), after the postback has occured, the value will always be empty/null.
Is this correct?
If so, is there anything else I can do that doesnt require an architectural change? Or something similar I can use to persist changes across post backs (Session[] no good unfortunately).
ViewState stores the state of the page (page and control settings + custom values stored in ViewState) between post backs. It is just hidden field with serialized (and encrypted) state data. When you set something to ViewState in code behind it is transfered with page markup to the client and posted back to the sever in the next Postback. The page life cycle (between InitComplete and PreLoad) deserializes state from ViewState. That is the reason why you can’t access data from ViewState in OnInit.