Solved

Nested user controls losing Viewstate

Posted on 2010-09-09
4
504 Views
Last Modified: 2012-05-10
Hi Experts

I have a user control (a drop down control) nested within another user control (a gridview) and am using Viewstate to keep track of the gridview SortDirection (ASC or DESC). This works fine, until the selected index is changed in the nested control and then that control needs to read this value from ViewState. At this point however the value is Nothing.

Is there a way of persisting Viewstate across nested user controls?

Thanks

Stewart
0
Comment
Question by:digital_soul
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:vusov
ID: 33636351
Try to use HttpContext.Current.ViewState, instead of simple ViewState
0
 
LVL 2

Author Comment

by:digital_soul
ID: 33636407
'VIewState' is not a member of System.Web.HttpContext so Visual Studio tells me.
0
 
LVL 2

Author Comment

by:digital_soul
ID: 33636458
Would I be better off just storing this value in the Session?
0
 
LVL 3

Accepted Solution

by:
vusov earned 500 total points
ID: 33636560
Sorry my miss, yes you can use System.Web.HttpContext.Current.Session. But you should remember that Session variable will be available on all pages and user controls.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question