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

Try-Catch ViewState Error

5 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 20 Feb 2014, 06:57 PM
Hi All,

I have any interesting set of requirements that I have implemented.  However, if one User has multiple tabs/windows of the RadGrid open ViewState errors, such as the one below, can occur.  Is there any way to place them in a try-catch of sorts so that the entire page doesn't error out?

[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
   System.Collections.ArrayList.get_Item(Int32 index) +10067188
   Telerik.Web.UI.GridColumnCollection.System.Web.UI.IStateManager.SaveViewState() +208
   Telerik.Web.UI.GridTableView.GetStructureState() +114
   Telerik.Web.UI.RadGrid.SaveTableViewStructure(ArrayList stateList, GridTableView tableView) +47
   Telerik.Web.UI.RadGrid.SaveViewState() +74
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +80
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +404
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3770

Thanks,
Mark

5 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 25 Feb 2014, 12:28 PM
Hi Mark,

I was unable to replicate the issue by opening a multiple tabs of RadGird. From the exception which you have received I noticed that you are trying to access an item outside of the collection. Could you please provide your code declaration and the related code behind for further investigation?

Regards,
Kostadin
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Mark
Top achievements
Rank 1
answered on 25 Feb 2014, 01:37 PM
This issue is unique to my setup: I have a C# all-code-behind SharePoint web-part with a Radgrid in it.  There is a drop-down-list that does a redirect to the same page, storing and retrieving the value in Page.Session and rebuilding the SqlDataSource and RadGrid based off of the new value.

This value is what the SqlDataSource uses as a Table to query the SQL Database.  The RadGrid is then assigned the SqlDataSource and is built off of a DataView pulled from the SqlDataSource (that way I can control the column types and implement the google-like-column-filtering functionality).

The issue occurs when a User opens up a new tab and navigates to a new value in the drop-down-list (rebuilding the SqlDatasource and RadGrid in the process) and then returns to the original tab and attempts to interact with the RadGrid (filtering for example).

Thanks,
Mark
0
Kostadin
Telerik team
answered on 28 Feb 2014, 12:55 PM
Hi Mark,

Instead storing and retrieving the value in Page.Session you could save them in the ViewState. This way the different grinds in the different tabs will be independent from each other.


Regards,
Kostadin
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Mark
Top achievements
Rank 1
answered on 28 Feb 2014, 02:13 PM
The User requires a drop-down-list be associated with the RadGrid that allows the changing of the SqlDataSource for the RadGrid.  I have to do a redirect to the page to rebuild the grid with the new datasource.

0
Kostadin
Telerik team
answered on 05 Mar 2014, 09:15 AM
Hello Mark,

In this case you could use the ViewState after you redirect to the page. For instance you choose an item from the drop down and save the value in a Session. Then you redirect to the same page and on Page_Load you save the value from the Session in a ViewState and clear the Session. This way you will make each tab independent.

Regards,
Kostadin
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Mark
Top achievements
Rank 1
Share this question
or