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

Loosing NestedViewTemplate On Page Index Change

3 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 02 Jun 2015, 06:35 PM

I created my own CompositeControl that extends and automates many tasks for me with the RADGrid. Posting the code in it's entirety is impossible because of how complex it is. But I am going to do my best to explain the gist of my problem and what I am  looking for.

I use the RADGrid almost entirely using Server-Side code (VB.Net flavor). Now ad the time I initialize my grid (at page load) I add a custom Template to the MasterTableView.NestedViewTemplate. The custom template is a class I created inheriting from ITemplate and implements the InstantiateIn method. I set the MasterTableView.HierarchyLoadMode = Client as well. The template I created simply displays additional fields on the same parent record (ie: row) that I manually have hidden from the RADGrid column list (for lack of space). If the user wants to see the additional information, expanding the nested view will show them the remaining fields.

The first time my page/grid load...works perfectly, the arrow appears on the left side of each record and if clicks it expands to show my custom NestedViewTemplate. However the problem I have is that I am also sometimes allowing for paging, and if the user changes the page I lose the NestedViewTemplate completely. The arrows to the left of each row vanish.

I have saved the ITemplate class into the ViewState so that I can "reattach" it if it is found to be missing at a later reload. I have looked all around to see at which point I need to reattach it, but no matter where I re-attach the NestedViewTemplate, it doesn't re-appear on a page index change.

My question is, at which event should I be re-attaching the NestedViewTemplate so that it is early enough in the event timeline that it can bind with the parent data and display on the RADGrid? I've tried Page_Init, Page_Load, and grid_DataBinding...no luck. When stepping through my code, I see that at the time that the PageIndex is changed, the NestedViewTemplate is loaded into the RADGrid. The only thing I noticed that is different is that in the initial load of the grid, the gridDataBinding() event is fired, but when the page index is changed it does not fire.

HELP!

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 05 Jun 2015, 11:39 AM
Hi Ben,

From the provided information I assume that the reason for that issue is either the way you are creating the NestedViewTemplate or the way you are binding the grid. Please make sure you are creating the templates on Page_Init event handler, so that the template controls can be added to the ViewState
Regards the databinding please make sure you are using advanced data binding through NeedDataSource event handler which is fired each time when the grid needs to be bound to the datasource.

Regards,
Kostadin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Ben
Top achievements
Rank 1
answered on 05 Jun 2015, 01:54 PM

Kostadin,

Thank you for answering my post.

I did try the Page_Init() event (as mentioned in my original post) but that did not work. The Page_Init() only runs the first time the page loads. When the user move to a different PageIndex in the grid, it causes a Partial-PostBack which does not refire the Page_Init() event and thereby I lose the NestedViewTemplate.

What I am currently trying to do is the following...

When I initially add the NestedViewTemplate class to the grid, I also add it's reference to a custom ViewState variable. In the Page_Load() event, I check to see if my custom ViewState has a NestedViewTemplate stored, if it does I check to see if the grid.MasterTableView.NestedViewTemplate is nothing. If it *is* nothing, then I place the NestedViewTemplate found in the custom ViewState variable back into the grid.MasterTableView.NestedViewTemplate.

However, I find that the grid_DataBinding() event does not fire on a Partial-PostBack...so it looks like it never renders the NestedViewTemplate again, which is why I lose the NestedView on the grid.

I tried adding code so that *if* it has to re-attached the NestedViewTemplate that is also calls the grid_Rebind() method. But now I am getting the following error:

InnerException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

 

This above error only happens if I try to rebind the grid during the Page_Load() event. If I take that line out, then the error goes away, but the NestedViewTemplate does not render.

 

-Ben

0
Kostadin
Telerik team
answered on 10 Jun 2015, 07:24 AM
Hello Ben,

Note that by replacing/changing the ViewState there is a big chance to break it. I assume that is the reason for receiving this error on your end. Note that the correct approach is to create the entire grid on Page_Init event handler and also create the NestedViewTemaplate there. Could you please provide your code declaration how the grid is create and also the related code behind in order to investigate the issue further? Additionally I would recommend you to examine the following help article which elaborates more on this matter.

Regards,
Kostadin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Ben
Top achievements
Rank 1
Share this question
or