Forum Moderators: open

Message Too Old, No Replies

User Control losing ViewState

(sometimes)

         

Jimmy Turnip

4:51 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



I've never experienced this problem before, but it is the first time I've used c# instead of vb, so it could be my dodgy code.

I have two User Controls on my page. When I click a button to cause a postback from the page everything works fine, but when I click a button in one of the user controls it seems like the ViewState is not persisted and the two User Controls appear without all the bound data that was in them before.

Has anyone else experienced this before and know what my problem might be or suggest a solution?

TheNige

7:50 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



what do your user controls have in them? datagrids? You may need to rebind after each postback...even if you are using viewstate because the underlying datasource is not being persisted.

Jimmy Turnip

8:18 am on Jun 22, 2005 (gmt 0)

10+ Year Member



One of the controls has a repeater bound from the database and the other has a few literals bound from a configuration file.

Why should I need to rebind the controls after postback if a button in the user control is clicked, but not if a button on the page is clicked? Surely the viewstate of the controls should be preserved in both instances?

TheNige

7:59 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



How do you add these controls to the page? Are they hard coded in the ASPX file? Or do you dynamically add them in the code behind?

Maybe try writing them in VB since you know how they should work to see what is going on.

Jimmy Turnip

10:19 am on Jun 23, 2005 (gmt 0)

10+ Year Member



Thanks TheNige. It was the fact I wasn't re-assigning the datasource. I just find it strange that I only had to to do this when the page was posted back from the user control. One of the controls works fine now, but the other containing the menu tabs doesn't.

I'm trying to put an array list into the viewstate to use as the datasource on postback. Problem is I get this error:

The type 'ebiz.tab' must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate.

I've tried setting the ebiz.tab to [Serializable()] and it still doesn't work. Any other ideas?

(I didn't post any code because it'd be quite long, but can do if it'd help)