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

RadGrid filtering throws null reference exception when inside a RadWindow

4 Answers 497 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 20 Sep 2011, 09:36 PM
I have a RadGrid in a RadWindow.  When I try to filter the grid it does a postback and throws this exception:

[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) +9792
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

I found that if I put another RadGrid on the page not in a RadWindow and filter it first, then filter the RadGrid in the window, it works correctly.

To reproduce: click "Open RadWindow", enter "5" in Title filter, click the filter icon for the Title column and select "Contains"

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="RadGridTest.aspx.vb" Inherits="RadGridTest" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Charting" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <a href="javascript:$find('RadWindow1').show();">Open RadWindow</a>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="True" VisibleTitlebar="true" VisibleStatusbar="false">
            <Windows>
                <telerik:RadWindow ID="RadWindow1" runat="server" Title="Change Dashboard" Width="500" Modal="true">
                    <ContentTemplate>
                        <telerik:RadGrid ID="RadGrid1" runat="server" PageSize="10" AllowPaging="true" AllowSorting="true">
                            <GroupingSettings CaseSensitive="false" />
                            <MasterTableView AutoGenerateColumns="false" AllowFilteringByColumn="true">
                                <Columns>
                                    <telerik:GridTemplateColumn AllowFiltering="false">
                                        <ItemTemplate>
                                            <asp:HyperLink ID="lnkSelect" runat="server" NavigateUrl='/Default.aspx'>Select</asp:HyperLink>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn HeaderText="Title" DataField="Title" SortExpression="Title" />
                                    <telerik:GridBoundColumn HeaderText="Description" DataField="Description" SortExpression="Description" />
                                </Columns>
                            </MasterTableView>
                        </telerik:RadGrid>
                    </ContentTemplate>
                </telerik:RadWindow>
            </Windows>
        </telerik:RadWindowManager>
    </div>
    <div>
        <telerik:RadGrid ID="RadGrid2" runat="server" PageSize="10" AllowPaging="true" AllowSorting="true">
            <GroupingSettings CaseSensitive="false" />
            <MasterTableView AutoGenerateColumns="false" AllowFilteringByColumn="true">
                <Columns>
                    <telerik:GridTemplateColumn AllowFiltering="false">
                        <ItemTemplate>
                            <asp:HyperLink ID="lnkSelect" runat="server" NavigateUrl='/Default.aspx'>Select</asp:HyperLink>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn HeaderText="Title" DataField="Title" SortExpression="Title" />
                    <telerik:GridBoundColumn HeaderText="Description" DataField="Description" SortExpression="Description" />
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>

Imports Telerik.Web.UI
Imports Telerik.Charting
Imports System.Data
Partial Class RadGridTest
    Inherits System.Web.UI.Page
 
    Private Shared Function GetGridDataTable() As DataTable
        Dim GridDataTable As New DataTable()
        GridDataTable.Columns.Add(New DataColumn("Title", System.Type.GetType("System.String")))
        GridDataTable.Columns.Add(New DataColumn("Description", System.Type.GetType("System.String")))
        For i As Integer = 0 To 4
            Dim Row As DataRow = GridDataTable.NewRow()
            Row.SetField("Title", "Title " & i)
            Row.SetField("Description", "Description " & i)
            GridDataTable.Rows.Add(Row)
        Next
        Return GridDataTable
    End Function
 
    Protected Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        RadGrid1.DataSource = GetGridDataTable()
    End Sub
 
    Protected Sub RadGrid2_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid2.NeedDataSource
        RadGrid2.DataSource = GetGridDataTable()
    End Sub
End Class

4 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 23 Sep 2011, 03:43 PM
Hello Josh,

I was able to replicate the problem on my side and forwarder your report to our developers for further investigation. Once I have any feedback from them, I am going to get back to you with the details.

Regards,
Martin
the Telerik team
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Svetlina Anati
Telerik team
answered on 26 Sep 2011, 05:09 PM
Hi Josh,

To fix the problem you should put the RadWindow with ContentTemplate outside the Windows collection of the RadWindowManager and use it as a separate control. You can show it by using show() instead of radopen/open.

 The problem you report comes from the fact that your RadWindow with ContentTemplate is added in a RadWindowManager Windows and Controls collections. At some point the RadWindowManager needs to clear its child controls and this is what causes the problem. The scenario of having a RadWindow with ContentTemplate declared in the RadWindowManager is not valid itself - it works for simple cases but the actual design purpose of the manager is to dynamically create RadWindow containers on the client and a RadWindow with ContentTemplate cannot be dynamically created on the client. We are aware of the issue and it is logged in our TODO for future investigation and improvement. However, I cannot give you a time estimate when it will be addressed due to the specifics of the problem, already set priorities and the fact that there is a simple and correct solution.

Please, test my suggestion of moving the RadWindow outside the manager  and let me know how it goes or in case you need any assistance.

All the best,
Svetlina Anati
the Telerik team
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Josh
Top achievements
Rank 1
answered on 30 Sep 2011, 09:29 PM
Thank you!  That fixed it.
0
BrianS
Top achievements
Rank 1
answered on 24 Jan 2012, 08:48 PM
I've encountered a similar scenario. i use a RadWindowManager and the ContentTemplate defines a usercontrol which gets dynamically loaded when the window is opened. I've discovered that if you rebind the grid in the prerender event, this scenario works fine.

protected void RadGridPayments_PreRender(object sender, EventArgs e)
{
   // a rebind is required for ajax request   (excel export not done in ajax request)
    if (!m_IsExport)
        RadGridPayments.Rebind();
}
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Martin
Telerik team
Svetlina Anati
Telerik team
Josh
Top achievements
Rank 1
BrianS
Top achievements
Rank 1
Share this question
or