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

Exception accessing .ClientID of GridTableRow

8 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Joel asked on 08 Aug 2014, 10:14 PM
FYI, when I access a GridTableRow object's ClientID, I get the following exception:

      Unable to cast object of type 'Telerik.Web.UI.GridTableRow' to type 'Telerik.Web.UI.GridItem'.

This happened during a postback after I added the Grouping option to a grid, then dragging a grid column into the grouping area.

I had some code walking through the controls on the page and looking at the ClientID which triggered the exception. I just added code to ignore the exception and kept going, but though you might be interested. I don't need a resolution, assuming it's not already fixed in latest release.

The line that throws the exception looks like this, oCurrent walks through all controls, and currently is a Telerik.Web.UI.GridTableRow:
      string sCurClientID = oCurrent.ClientID;

I'm using telerik release 2014 Q1 on a Win7 VS 2012 developer machine.

8 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 13 Aug 2014, 08:48 AM
Hi Joel,

The described issue is very strange. We have not encountered it so far and we are not sure what could be the reason for it. Could you please post the entire code behind code.  Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.

Looking forward for your reply.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Joel
Top achievements
Rank 1
answered on 14 Aug 2014, 05:14 PM
It certainly seemed odd. I worked around it, so not an urgent problem for me, just... odd. 

I can't publish our internal framework, and it's large enough to not be that helpful, but I can try to pull the scenario out, a call stack, and so forth. The RadGrid is assigned 

This happens in our page's Render handler. That calls into our framework's render handling, which walks the controls on the page to make sure the right control/subcontrol has focus (recursively digging into complex controls).

Here's the call stack for the exception, starting when the server's render starts, through the framework and recursive walk, to Telerik's get_ClientID:
at Telerik.Web.UI.GridTableRow.get_ClientID()
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 566
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 599
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 599
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 599
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 599
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 599
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 599
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 599
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 599
at X.Components.Page.BasePage.GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 599
at X.Components.Page.BasePage.GetFocusControl() in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 544
at X.Components.Page.BasePage.Render(HtmlTextWriter w) in q:\XCore\Projects\XLEDGER.NET\XLEDGER.NET\XLib\Components\Page\BasePage.cs:line 349
at X.Components.Page.BasePageEx.Render(HtmlTextWriter output) in q:\XCore\Projects\XLEDGER.NET\X\App_Code\Components\Page\BasePageEx.cs:line 157
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

And here's a simplified version of the recursive search:
public Control GetNextFocusControl(Control oCurrent, Control oPrevious, Boolean& bPreviousPassed, Control& oFirst)
 {
    // Exception happens here:
    string sCurClientID = oCurrent.ClientID;
     
    // [snip] - test oCurrent's client id with oPrevious and react appropriately
  
    // Search next recursively (depth first)
    foreach (Control c in oCurrent.Controls)
    {
        System.Web.UI.Control oNext = GetNextFocusControl(c, oPrevious, ref bPreviousPassed, ref oFirst);
         
        // if oNext is the control we are searching for, return oNext
        // return oNext;
    }
     
    return null;
}

The RadGrid is based on the telerik grouping grid demo, and is assigned a type dataset's datatable:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
 {
     if (DataSet != null && DataSet.xgl_balance != null)
     {
         (sender as RadGrid).DataSource = DataSet.xgl_balance;
     }
}
0
Radoslav
Telerik team
answered on 18 Aug 2014, 06:51 AM
Hi Joel,

Based on the provided information is very hard to say what the reason for getting the described error is. Could you please try isolating the problem into the simple example? Thus we will be able to debug the project and provide you with more to-the-point answer.

Looking forward for your reply.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Joel
Top achievements
Rank 1
answered on 18 Aug 2014, 02:42 PM
That's OK, my friend. As I said, not a problem I need a fix for, just something strange I saw that I thought might be helpful for you to see. I can't justify the time to isolate this issue in a trivial project with the upcoming deadline, so let's just let this one go. If someone else runs into it, at least they won't be the first. :) Thanks for taking a look and giving it a try!
0
Scott
Top achievements
Rank 1
answered on 16 Sep 2014, 01:34 PM
Here's how I encountered this exeption: "Unable to cast object of type 'Telerik.Web.UI.GridTableRow' to type 'Telerik.Web.UI.GridItem'." using Telerik 2013.3.1324.40.

I have a page with basic asp.net and telerik controls (including several grids) contained in various user controls on the page. I needed to find a child control whose validator failed so that I could highlight it, so I wrote a method that would recursively look for all page's child controls to find a match. When I get to the GridTableRow control, this exception is thrown. Below is my FindControlRecurisve() method:

        public static Control FindControlRecursive(Control control, string clientId)
        {
            foreach (Control c in control.Controls)
            {
                if (c.ClientID == clientId)
                {
                    return c;
                }

                Control childControl = FindControlRecursive(c, clientId);
                if (childControl != null)
                {
                    return childControl;
                }
            }

            return null;
        }

The Telerik source code I have has this for GridTableRow.ClientID:

        public override string ClientID
        {
            get
            {
                return String.Format("{0}__{1}", Parent.Parent.ClientID, ((GridItem)this).ItemIndexHierarchical);
            }
        }

Looks to me like "this" cannot be cast to a GridItem because "this" = GridTableRow and GridTableRow is derived from TableRow which is derived from WebControl (ie, not GridItem).
 

0
Marvin
Top achievements
Rank 1
answered on 22 Oct 2015, 03:17 PM
This is a current issue for me...are there any solutions?
0
Joel
Top achievements
Rank 1
answered on 22 Oct 2015, 03:24 PM

I wasn't interested in the sub-controls that threw the exception, so I just caught the exception, ignored the control, and moved on with the page search for the controls I was interested in.

Your situation may vary, but maybe you can get away with it too?

0
Marvin
Top achievements
Rank 1
answered on 22 Oct 2015, 03:26 PM
Yeah...I may end up doing something similar...thanks
Tags
Grid
Asked by
Joel
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Joel
Top achievements
Rank 1
Scott
Top achievements
Rank 1
Marvin
Top achievements
Rank 1
Share this question
or