Recommendable stuff...

Friday, March 9, 2007

ViewState in user control / child user controls

So i have a page which loads a user control, call it ctrlA and ctrlA has a user control ctrlB, which is loaded at runtime when i click a button.
I load my page, ctrlA is loaded and everythings looks good. i hit my button, and ctrlB is loaded. No problem.
Now ctrlB also has a button, when i hit this, the page gives me an error saying "The cast is invalid". What in the world happened?!
I found the problem.
In ctrlA if have a property that reads viewstate("Mode").
I also have the same property in ctrlB. So when the page hits a postback, and the 'LoadViewState' event fires, the page seems to go bonkers when it (i assume) tries to read the second viewstate("Mode") into memory.
I renamed the viewstate variable to use a different name in ctrlB and everything went fine.

0 ppl said stuff:

Get the new version of Firefox!