We are currently using version 2015.2.826 of Telerik controls. We are getting intermittent exceptions from one of our pages where we have codebehind for handling the grid events. The error we are getting is:
Unable to cast object of type 'System.EventArgs' to type 'Telerik.Web.UI.GridPageChangedEventArgs'
We have searched for any other customers with this problem, but are not able to find anything. We definitely need your help on this production problem.
Thank you,
Ed Sudit
4 Answers, 1 is accepted
As the error states, you are trying to cast "System.EvetArgs" type to "Telerik.Web.UI.GridPageChangedEventArgs", so please examine your code-behind and see if the event parameters that you are using in the event handlers are of correct type and if you are not trying to cast "System.EvetArgs" type to "Telerik.Web.UI.GridPageChangedEventArgs".
If further assistance is needed, please provide the code-behind of your RadGrid, so we can take a look at your implementation.
Regards,
Konstantin Dikov
Telerik
Hello Konstantin,
We are not doing an implicit cast. The code is very straight forward where we are handling an event from the RadGrid in our codebehind. Here is the partial code that seems to be throwing this exception intermittently:
ASPX:
<Telerik:RadGrid ID="grdReceivedEmails" runat="server" AutoGenerateColumns="false"
AllowPaging="true" AllowSorting="true" OnSortCommand="grdReceivedEmails_SortCommand"
OnPageSizeChanged="grdReceivedEmails_PageSizeChanged"
OnPageIndexChanged="grdReceivedEmails_PageIndexChanged"
OnSelectedIndexChanged="grdReceivedEmails_PageIndexChanged"
CellPadding="0" CellSpacing="0" AllowMultiRowSelection="false">
VB Code:
Protected Sub grdReceivedEmails_PageIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridPageChangedEventArgs)
grdReceivedEmails.CurrentPageIndex = e.NewPageIndex
BindReceivedEmails()
End Sub
You have attached the same event handler, as for the OnPageIndexChanged event, to the OnSelectedIndexChanged event, which is the cause of the problem. Please set different event handler for the OnSelectedIndexChanged event with EventArgs as a second argument:
Protected
Sub
RadGrid1_SelectedIndexChanged(sender
As
Object
, e
As
EventArgs)
....
End
Sub
Best Regards,
Konstantin Dikov
Telerik
Hello again,
Please disregard my previous post. After pasting the code snippet, I realized what was being done incorrectly. The OnSelectedIndexChanged event was being handled by a method that should not be handling it. The implicit event argument was failing due to that.
Thank you for your reply, I've corrected the code now.
Ed Sudit