Using VeiwState on an ASPX page

I have read everything I can get my hands on about ViewState but can't seem to figure out what I'm doing wrong.

In a sub routine that first and foremost fills a grid, I set the value of two controls and then save those to view state:

                    ViewState.Item("SortKey") = SortKey.Value
                    ViewState.Item("RecId") = RecId.Value

I'm using ViewState because I can't seem to get the control values to persist.

On Page_Load I try to retrieve those values into the controls:
            SortKey.Value = ViewState.Item("SortKey")
            RecId.Value = ViewState.Item("RecId")

This does not work.

What am I missing?


Thanks
LVL 4
g_johnsonAsked:
Who is Participating?
 
Ryan ChongCommented:
it should working fine with ViewState statements you posted above.

how you calling that sub routine? is it before the postback event?
0
 
Ryan ChongCommented:
On Page_Load I try to retrieve those values into the controls:

SortKey.Value = ViewState.Item("SortKey")
            RecId.Value = ViewState.Item("RecId")
are you doing this in the same page in where you set the viewstate values?
0
 
g_johnsonAuthor Commented:
Yes, and it's enclosed in an "If postback" block, which I should have made clear.
0
 
g_johnsonAuthor Commented:
You are correct that it should work as written.  We believe that because we are using a proprietary control on the page and that's where ViewState is captured that it's not in a good spot during the life cycle of the page.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.