This is a migrated thread and some comments may be shown as answers.

ViewState Problems

7 Answers 430 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 01 Aug 2013, 08:18 PM
I've got a general ViewState question. Here's how I'm using Telerik and Ajax in my Web App.

1. Using an .aspx page as the shell that loads a web user control (.ascx) that acts as sort of a master page to additional (.ascx) pages based on what the user selects. So Master.ascx has a tree control and this tree envokes different .ascx pages to load on the right side of the page based on what users select.

2. I've got a class that is keeping a session variable to remember data based on user clicks

So, all is well until I open a second window and cut and paste the same exact URL into it. 
I'm not forced to login it just opens just like the original window.

Here's where it gets hairy. If I start to click in Window 2, I am able to load all of the secondary .ascx pages as I go without any issues. Now if I go back to Window 1 I get all sorts of errors referring to ViewState not being able to load.....

This error seems very generic and I'm unable to get to the bottom of it. Any ideas where I should start looking?

Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
http://localhost/PDMPlanroom/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=ctl00_ctl00_rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSystem.Web.Extensions%2c+Version%3d3.5.0.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d31bf3856ad364e35%3aen-US%3a7263e9c6-5962-41bc-b839-88b704bfcf0d%3aea597d4b%3ab25378d2
Line 15

7 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 06 Aug 2013, 10:24 AM
Hello,

Thank you for contacting us.

This behavior could be observed if you are sharing the ViewState of the user controls between the pages. In such case while you change the controls in one windows the other controls that are already loaded does not know about the modification in the other window and when the ViewState is restored it is failing because the controls are different from the last time.

You could avoid this behavior by loading each and every time the user controls on the page not only when the user has requested them. You could hide the not needed controls with the help of the Visible property.

I hope the provided information helps.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Jay
Top achievements
Rank 1
answered on 06 Aug 2013, 06:46 PM
Andrey,
Follow up question to your suggestion of loading the controls each and every time.
What do you mean by load?

I've got 2 master pages(1 nested inside the other) and then inside of that I have a page that loads a web user control with the main "meat" of the page being on the left side and the right side is other .ascx pages that are loaded based on what the user clicks on the main .ascx page. Some of these pages are doing the main bulk of their "work" in OnInit, and some in PageLoad or even PreRender. Does that make a difference?

Also, If a page is just using a grid and there is none of the above and I'm just depending on the "NeedDataSource" Event to fire could that also play a role in my ViewState issues?

I'd attach a sample project but it'd be pretty complicated to re-create it via sample size.

It gets confusing when dealing with Page LifeCycle and ViewState for me. It's an ongoing issue that I've struggled with and to this day still haven't grasped it fully.

Thanks,
Jason
0
Andrey
Telerik team
answered on 09 Aug 2013, 06:54 AM
Hi,

By loading I mean using the LoadControl method on Page_Init or on Page_Load as described in this help topic. In order for the ViewState to be persisted you need to make sure you have one and the same controls on each postback not only when the user clicks on the button.

NeedDataSource does not affect the ViewState and do not cause any problems with it.

If you need further clarification or have more question, please share the full page source code along with the code-behind file content of the page in question, elaborate a bit more on the questions you have and we will be glad to help you.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Jay
Top achievements
Rank 1
answered on 14 Aug 2013, 03:17 PM
Andrey,
I'm still struggling with this issue. I'm able to figure out how to load the .ascx controls, but do you think I need to load all of the Telerik controls on the page as well? Does this mean I wouldn't be able to have them in the markup?

We are in a situation where we will be going into production real soon and it's starting to cause panic among the team.
Is it possible to do a paid support session and demo the functionality that is failing via remote web (GoToMeeting)?
Thanks,
Jason
0
Andrey
Telerik team
answered on 15 Aug 2013, 01:53 PM
Hello,

I am not sure what you mean by all other controls. Could you elaborate a bit?

About the session request, I am afraid that we do not provide such service yet. However, if you want to speed up things you could open a forma support ticket and relate to this forum thread. Thus you would get better response time and you could send me a sample version of your project which I could run locally and thus to help you.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Jay
Top achievements
Rank 1
answered on 16 Aug 2013, 02:15 PM
I've attached a screen shot (viewstate_issues.gif) of what happens when I run the same web app side by side in the same browser. It includes what Firebug is telling me when using it to try to debug this issue.
 Here's a few specifics:
1. Cookies are used to keep track of last selected folders when on the documents page
2. An object kept in session is used to keep track of the projects the user has open and active and also what page the user has selected for that project. (ie in the tab'd interface you could have project A open and the Documents page selected, then also have Project B open and have Invitees selected. These are stored so when you navigate back it remembers where you left off)
3.ViewState errors are being thrown by the Telerik .axd files and I'm unable to determine exactly what the issue is and how to solve it.

Any thoughts?
Jason
0
Andrey
Telerik team
answered on 19 Aug 2013, 11:41 AM
Hello,

Please try to disable the Ajax by setting the EnableAjax property of RadAjaxManager or RadAjaxPanel to false and then the exception will be thrown on the server.

Additionally, please share the full page source code of the page in question along with the code-behind file content. Thus all the people who want to help you will have better understanding of your case.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
General Discussions
Asked by
Jay
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Jay
Top achievements
Rank 1
Share this question
or