Hi guys,
I have that scenario writen in the subject. My problem is that the ViewState is totally lost in the usercontrol when the user selects another view of the multiview.
Do you know if this scenario should be supported by ASP.NET?
Kind regards
How do you know that the ViewState is lost? Are you saving anything in ViewState from UserControl? Please explain in more detail and if possible also post some code in UserControl.
- Sujit
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
It is lost because the content of the TextBoxes inside the user control lose its contents when you switch the view that is active in the multiview. Y also tried to debug it storing something in the viewstate and the value it is not there when you have to retrieve it.
The code is too heavy to post it here.
Simply create a UserControl with a TextBox in it
In the Page, create a Multiview with two views
In one view add a WebPartZone.
In the WebPartZone add the UserControl
Create a button or menu to switch between the views of the multiview
Run
Type something in the TextBox of the WebPart.
Switch the view
Switch back the view
The text is missing!!
Is that a bug or am I doing something wrong?
Hi,
Based on your description, we've made a test and the ViewState works. I don't know how do you handle the ViewState in your code, here, just provide a sample we made for you to refer. And remember that all the EnableViewStates attribute should be true (The default is true).
UserControl:
0
![]()
Nai 9/7/2007 2:59:26 AM
I don't understand why you have to store the viewstate manually. If you also instantiate the usercontrol in the view1, outside the webpartzone, the viewstate is kept automatically without writing any code.
Hi,
First, the textbox is in your UserControl and the ViewState is used to store the value in that textbox, so the viewstate should be declared in User control level.
Second, the code in my samples just indicates that if you store a value in ViewState, the changes between views would not cause the ViewState's losing.
Third, what do you mean by "the viewstate is kept automatically without writing any code?" if I created an instance of the usercontrol, i have to assign the text propery exposed by that control with the values,right? And the values be stored in ViewStates(this can be done by the codes in user control), after changing the views, I still can see the text in textbox which indicates that the value in viewstate do exist, right? Of course, keeping viewstates do not need to write codes, but the above codes is just an executable sample for you to know the viewstate would not lost even you have changed the views.
Thanks.
Michael Jin.
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.