HierarchyLoadMode causes javascript error when set to Client

12 posts, 1 answers
  1. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 20 Jan 2010 Link to this post

    Hi,
    I have a problem that only seems to occurs when the HierarchyLoadMode is set to Client. I have used the client mode in other similar scenarios and have not had any problems.
    I load up an intial page in a rad window. This rad window contains a user control. This user control contains a rad grid summary, amongst other things.
    The rad grid summary contains a master table and one detail table. The tables are databound using NeedDataSource and DetailTableDataBind. The grid has a column containing a link that launchs a different rad window which allows you to edit and save some related data. When you close the rad window, it fires the OnWindowClose hook of the radwindow and causes an ajax post back of the control that contains the rad grid (i.e. the controls contained in the original rad window). This all works fine until you expand one of master table rows.

    If you expanded one of the items,and then try to open the second rad window again by clicking on that link in the radgrid column, then close the radwindow (hence triggering the ajax update to the control containing the grid), you get the error:

    "Specified argument was out of the range of valid values.
    Parameter name: ItemHierarchicalIndex"


    This only occurs if HiearchyLoadMode is set to client. Setting it to ServerBind and ServerOnDemand is fine. I have the same exact setup somewhere else, and it is working ... So i must be doing something silly in this particular example. Would appreciate it if I could get some help.

    The control containing the RadGrid:
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGridSummary"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGridSummary" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 
    <div class="BaseSummary" id="BaseSummaryDiv" runat="server"
        <div class="BaseSummaryControl"
            <telerik:RadGrid ID="RadGridSummary" runat="server" PageSize="10" AutoGenerateEditColumn="false" 
                GridLines="None" BorderStyle="Solid" AllowMultiRowSelection="true"
                <ClientSettings Selecting-AllowRowSelect="true"
                </ClientSettings> 
                <MasterTableView DataKeyNames="SecurityGuardAvailabilityTemplateId" CurrentResetPageIndexAction="SetPageIndexToFirst" 
                    Dir="LTR" TableLayout="Auto" Frame="void" CommandItemDisplay="None" GridLines="Horizontal" HierarchyLoadMode="Client" 
                    AutoGenerateColumns="false"
                    <NoRecordsTemplate> 
                        <div> 
                            There are no records to display</div> 
                    </NoRecordsTemplate> 
                    <Columns> 
                        <telerik:GridTemplateColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
                            ForceExtractValue="None" HeaderText="Availability Times" UniqueName="ShiftName"
                            <ItemTemplate> 
                                <asp:Label ID="guardAvailabilityTime" runat="server"></asp:Label> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                    </Columns> 
                    <ParentTableRelation> 
                        <telerik:GridRelationFields DetailKeyField="TemplateId" MasterKeyField="SecurityGuardAvailabilityTemplateId" /> 
                    </ParentTableRelation> 
                    <DetailTables> 
                        <telerik:GridTableView Name="DaysTable" DataKeyNames="TemplateId" AutoGenerateColumns="false"
                            <Columns> 
                                <telerik:GridBoundColumn HeaderText="Day" UniqueName="DayName" DataField="DayName"
                                </telerik:GridBoundColumn> 
                                <telerik:GridDateTimeColumn HeaderText="Start Time" UniqueName="StartTime" DataField="StartTime" 
                                    DataFormatString="{0:HH:mm}"
                                </telerik:GridDateTimeColumn> 
                                <telerik:GridDateTimeColumn HeaderText="End Time" UniqueName="EndTime" DataField="EndTime" 
                                    DataFormatString="{0:HH:mm}"
                                </telerik:GridDateTimeColumn> 
                            </Columns> 
                        </telerik:GridTableView> 
                    </DetailTables> 
                    <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
                        Resizable="False" Visible="False"
                        <HeaderStyle Width="20px" /> 
                    </ExpandCollapseColumn> 
                    <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
                        Visible="False"
                        <HeaderStyle Width="20px" /> 
                    </RowIndicatorColumn> 
                </MasterTableView> 
            </telerik:RadGrid> 
        </div> 
    </div> 




    This is the code that populates the grids:
    void RadGridGuardSummary_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) 
        { 
            if (e.DetailTableView.Name == "DaysTable") 
            { 
                GridDataItem parentRow = e.DetailTableView.ParentItem; 
                int securityGuardAvailabilitiesTemplateId = (int)parentRow.OwnerTableView.DataKeyValues[parentRow.ItemIndex]["SecurityGuardAvailabilityTemplateId"]; 
                SomeDataRecord rec = SomeDatatable.GetRecord(securityGuardAvailabilitiesTemplateId.ToString(), false); 
                e.DetailTableView.DataSource = DateTemplate.DayTemplate.GenerateDayTemplates(rec); 
            } 
        } 
     public void RadGridSummary_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
        { 
             DataTable data = this.GetData(); 
             if (data != null) 
                { 
                    RadGridSummary.DataSource = data
                } 
        } 

    This is the javascript that is called when the radwindow is closed:
    function OnRadWindowClose() { 
                    var oWnd = GetRadWindow(); 
                    var parentWindow = oWnd.GetWindowManager().GetWindowByName("StandardWindow"); 
                    var contentFrame = parentWindow.GetContentFrame(); 
                    contentFrame.contentWindow.RefreshControls(); 
                    oWnd.Close(); 
                } 

    This is the RefreshControils method:
    function RefreshControls() { 
                    var ajaxManager = $find("<%=RadAjaxManager1.ClientID%>"); 
                    if (ajaxManager != null) { 
                        ajaxManager.ajaxRequest("Refresh"); 
                    } 
                    return
                }        

    This is the AjaxUpdate method
    void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) 
        { 
            if (e.Argument == "Refresh"
            { 
                ReloadRecord(); 
            } 
        } 

    Again, any help will be much appreciated. This one has me stumped
  2. Venkat
    Venkat avatar
    7 posts
    Member since:
    May 2009

    Posted 21 Jan 2010 Link to this post

    I have similar problem with the Grid. The rad grid contains a master table and one detail table. The tables are databound using NeedDataSource and DetailTableDataBind. I have  HierarchyDefaultExpanded  set to true. Everything works fine on the page until I expand/collapase one of master table rows.
    I get the following error as well...

    "Specified argument was out of the range of valid values.
    Parameter name: ItemHierarchicalIndex"


    As the other post mentioned it only occurs if HiearchyLoadMode is set to client. Setting it to ServerBind and ServerOnDemand is fine. Any help is greatly appreciated.

    Thanks
    Venkat
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 21 Jan 2010 Link to this post

    I managed to solve the problem, but I still dont understand what was causing it.

    In my pages init event, i was iterating through all the controls on my page recursively by calling a custom method called 'FindControl', trying to find a particular control. If i commented out that code, or if moved it to the pre-render, everything started working fine

    I have no idea why it was having any effect on the code

    The offending code is below. If i commented out the call to 'FindControl' or moved it to the pre-render, it all worked fine.

    public static Control FindControl(Page page, string idToFind) 
            { 
                Control controlFound = null
     
                for (int i = 0; i < page.Controls.Count; i++) 
                { 
                    //Cast it to type of webControl 
                    Control ctl = page.Controls[i] as Control; 
                     
                    if (ctl != null
                    { 
                        controlFound = FindControlRecursively(ctl, idToFind); 
                        if (controlFound != null
                        { 
                            break
                        } 
                    } 
                } 
     
     
                return controlFound; 
            } 
     
            public static Control FindControlRecursively(Control webControl, string idToFind) 
            { 
                Control controlFound = null
     
                if (webControl.ID == idToFind) 
                { 
                    controlFound = webControl; 
                } 
                else 
                { 
                    if (webControl.Controls.Count > 0) 
                    { 
                        for (int i = 0; i < webControl.Controls.Count; i++) 
                        { 
                            Control ctl = webControl.Controls[i] as Control; 
                            if (ctl != null
                            { 
                                controlFound = FindControlRecursively(ctl, idToFind); 
     
                                if (controlFound != null
                                { 
                                    break
                                } 
                            } 
                        } 
                    } 
                } 
     
                return controlFound; 
            } 

  5. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 26 Jan 2010 Link to this post

    Hi EmpowerIT,

    One of the possible reasons for this error is when you try to get the control by its ID from the details tables but it does not exist. Please note that on Page_Init the grid is not bound yet and therefore the nested table views are not created. However in PreRender event (when you set HierarchyLoadMode to client) all grid table views are created and you can properly get a control by its ID.

    Additionally could you please send us a small runnable project which we will be able to debug locally for further investigation? You could open a formal support ticket from your Telerik account and attach a ZIP file there. Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.

    I hope this helps.

    Greetings,
    Radoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 26 Jan 2010 Link to this post

    Hi,
    ive logged the ticket (Your ticket ID is : 276598) with a project that reproduces the problem.
  7. Answer
    Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 29 Jan 2010 Link to this post

    Hi EmpowerIT,

    We have already answered you in the other thread you have posted on teh same subject. For your convenience I am pasting the answer here:

    When you expand a RadGrid item, its expanded state and ItemIndexHierarchical is saved in the control ViewState. This state is retrieved during the LoadviewState event. However, when you find the RadGrid  and you are try to get its Controls collection (webControl.Controls.Count), the get method of Controls property calls a method which tries to ensure creation of all items. However the items is not created yet and the hierarchy does not exist either because the OnInit event fires before the LoadViewState.

    On the other hand, when you perform postback without expanding any item, the RadGrid state is not changed, so it does not try to recreate its state and exception is not thrown.


    We will be glad to assist you with anything else, so do not hesitate to contact us again.


    Kind regards,
    Radoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Leo
    Leo avatar
    4 posts
    Member since:
    May 2010

    Posted 04 Nov 2010 Link to this post

    Hi,

    I am having similar issue. When i set the HierarchialLoadMode = "Client" the expand and collapse functionality works great. But once i have expanded a row, any other item command is throwing "Specified argument was out of the range of valid values.Parameter name: ItemHierarchicalIndex" error. No idea on how is this happening. I am not able to track the error, as the error occurs even before the page loads.

    Here is my scenario:
    I have Hierarchial Radgrid in my usercontrol and the Hierarchial load mode is set to client. I have a linkbutton in one of the columns in mastertableview and have two buttons in the commandItemTemplate. When i click and expand a row, the detail table is rendered and everything looks good. But after that, if i click on the linkbutton or the buttons in my commandItemTemplate, it throws the specified error. "Specified argument was out of the range of valid values.Parameter name: ItemHierarchicalIndex" error. Please Help, i have been struggling with this for whole day today. Any immediate response is much appreciated.

    Thanks,
    Leo.
  9. Leo
    Leo avatar
    4 posts
    Member since:
    May 2010

    Posted 09 Nov 2010 Link to this post

    Does anyone know the answer for my issue. I created a separate sample project with just my page and the usercontrol and couldnt recreate this issue. But i still couldnt figure out the issue in my original solution. the differences between the sample project and my original project is:

    Original Project has
    -Read/Write Session variables.
    -Get all the data from database
    -Implements another base page
    -the page inherits a master page
    -the page has 5 other usercontrols.

    I can only figure that the viewstate of the page is somehow lost after i expand a row. But i still dont know on how to set it back.
    Telerik team ,please provide your inputs. Its urgent and any help is highly appreciated.

    Leo.
  10. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 09 Nov 2010 Link to this post

    Hi Leo,
    If you paste some samples of your code it would assist in helping
  11. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 10 Nov 2010 Link to this post

    Hi Leo,

    Could you please elaborate a bit more on your scenario. How do you create the hierarchical RadGrid declaratively or programmatically? How do you bind it - using declarative relations or using advanced data-binding with DetailtableDataBind event? Also It will be helpful if you send me a small runnable example which demonstrates the issue or post your pages code here. You could open a formal support ticket from your Telerik account and attach a ZIP file there. In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.

    Looking forward for your reply.

    Best wishes,
    Radoslav
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  12. Leo
    Leo avatar
    4 posts
    Member since:
    May 2010

    Posted 10 Nov 2010 Link to this post

    Hi Radoslav,

    Thanks for you reply. I am not able to attach my sample project (.zip) in the forum. However, this is the same which already submitted to you as a ticket. Please refer to support ticket #363764.

    Any help is much appreciated.

    Thanks,
    Leo.
  13. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 11 Nov 2010 Link to this post

    Hi Leo,

    To avoid duplicate posts, I suggest you continue the communication on the referred support ticket. Also I am posting the answer here in case if someone else has the same problem:
    One possible reason for this error is if you are trying to change the item in the grid during rebind.
    Additionally, I notice that you are populating the detail table using the NeedDataSource event handler. Please have in mind that you should write the code for constructing detail data-source (list of objects) that will be used by the table to be bound to the hierarchical structure in the DetailTableDataBind event handler. In a NeedDataSource event you should bind only the master table view of the grid.


    Sincerely yours,
    Radoslav
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017