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

RadWindow Contain RadGrid

2 Answers 154 Views
Window
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 02 Jul 2012, 08:17 PM
Update the radgrid on the client side, then open the radwindow.

Generates errors:

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object. Telerik.Web.UI.WebResource.axd:6 


Code C#:

using System;
 
public partial class MLDefault : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
 
    protected void rgGrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        if (!IsPostBack)
        {
            rgGrid.DataSource = new System.Data.DataTable();
            return;
        }
 
        var list = new[]{
            new{
                Description = "Text 1"
            },
            new{
                Description = "Text 2"
            }
        };
 
        rgGrid.DataSource = list;
    }
}


Code ASP.NET:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MLDefault" %>
 
<!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">
 
    <script type="text/javascript">
        function OpenWindow() {
            $find('<%= rgGrid.ClientID%>').get_masterTableView().rebind();
            $find('<%= rwGrid.ClientID %>').show();
        }
    </script>
 
    <telerik:RadScriptManager ID="ScriptManager" runat="server" />
    <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rgGrid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgGrid" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <input type="button" value="Search" onclick="javascript:OpenWindow();" />
    <telerik:RadWindowManager ID="RadWindowManager" runat="server" EnableShadow="True"
        Behaviors="None" InitialBehaviors="None" ShowContentDuringLoad="False" VisibleStatusbar="False"
        Modal="true" RestrictionZoneID="aspnetForm">
        <Windows>
            <telerik:RadWindow ID="rwGrid" runat="server" Behaviors="Close,Move">
                <ContentTemplate>
                    <telerik:RadGrid ID="rgGrid" runat="server" AutoGenerateColumns="False"CellSpacing="0"
                        GridLines="None" OnNeedDataSource="rgGrid_NeedDataSource">
                        <MasterTableView AllowSorting="False">
                            <NoRecordsTemplate>
                                <div>
                                    Empty</div>
                            </NoRecordsTemplate>
                            <Columns>
                                <telerik:GridBoundColumn DataField="Description" />
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                </ContentTemplate>
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
    </form>
</body>
</html>

Thanks for the help.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Jul 2012, 05:34 AM
Hi David,

You should never call the Rebind() method in a NeedDataSource event handler. I have made some modifications in your code which works as expected. Here is the sample code.
aspx:
<telerik:RadScriptManager ID="ScriptManager" runat="server" />
    <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rgGrid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgGrid" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <input type="button" value="Search" onclick="javascript:OpenWindow();" />
    <telerik:RadWindowManager ID="RadWindowManager" runat="server" EnableShadow="True"
        Behaviors="None" InitialBehaviors="None" ShowContentDuringLoad="False" VisibleStatusbar="False"
        Modal="true" RestrictionZoneID="aspnetForm">
        <Windows>
            <telerik:RadWindow ID="rwGrid" runat="server" Behaviors="Close,Move">
                <ContentTemplate>
                   <telerik:RadGrid ID="rgGrid" runat="server" AutoGenerateColumns="False" CellSpacing="0"
                        GridLines="None" onneeddatasource="rgGrid_NeedDataSource1" >
                        <MasterTableView AllowSorting="False">
                            <NoRecordsTemplate>
                                <div>
                                    Empty</div>
                            </NoRecordsTemplate>
                            <Columns>
                                <telerik:GridBoundColumn DataField="Description" />
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                </ContentTemplate>
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
</div>
    </form>
</body>
</html>
 <script type="text/javascript">
     function OpenWindow() {
 
         $find('<%= rgGrid.ClientID%>').get_masterTableView();
         $find('<%= rwGrid.ClientID %>').show();
     }
    </script>
C#:
protected void rgGrid_NeedDataSource1(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
   {
     var list = new[]{
           new{
               Description = "Text 1"
           },
           new{
               Description = "Text 2"
           }
       };
 
       rgGrid.DataSource = list;
   }

Thanks,
Shinu.
0
David
Top achievements
Rank 1
answered on 03 Jul 2012, 02:56 PM
Shinu, thanks for your answer.
Client-side search:

works great if the RadGrid is not within a RadWindow...

Code c#:
using System;
using System.Linq;
 
public partial class MLDefault : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
 
    protected void rgGrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        if (!IsPostBack)
        {
            // To show NoRecordsTemplate
            rgGrid.DataSource = new System.Data.DataTable();
            return;
        }
 
        var list = new[]{
                new{
                    Description = "Text1"
                },
                new{
                    Description = "Text2"
                }
            };
 
        var lSearch = list.Where(i => i.Description.ToLower().Contains(txtText.Text.ToLower()));
        rgGrid.DataSource = lSearch;
    }
}


Code ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MLDefault" %>
 
<!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">
 
    <script type="text/javascript">
        function OpenWindow() {
            $find('<%= rwGrid.ClientID %>').show();
            $find('<%= rgGrid.ClientID%>').get_masterTableView().rebind();
        }
    </script>
 
    <telerik:RadScriptManager ID="ScriptManager" runat="server" />
    <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rgGrid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgGrid" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <input type="button" value="Open & Search" onclick="javascript:OpenWindow();" />
    <asp:TextBox ID="txtText" runat="server" />
    <telerik:RadWindowManager ID="RadWindowManager" runat="server" EnableShadow="True"
        Behaviors="None" InitialBehaviors="None" ShowContentDuringLoad="False" VisibleStatusbar="False"
        Modal="true" RestrictionZoneID="aspnetForm">
        <Windows>
            <telerik:RadWindow ID="rwGrid" runat="server" Behaviors="Close,Move">
                <ContentTemplate>                   
                    <telerik:RadGrid ID="rgGrid" runat="server" AutoGenerateColumns="False" CellSpacing="0"
                        GridLines="None" OnNeedDataSource="rgGrid_NeedDataSource">
                        <MasterTableView AllowSorting="False">
                            <NoRecordsTemplate>
                                <div>
                                    Empty</div>
                            </NoRecordsTemplate>
                            <Columns>
                                <telerik:GridBoundColumn DataField="Description" />
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                </ContentTemplate>
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
    </form>
</body>
</html>

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object. Telerik.Web.UI.WebResource.axd:6 

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) +3716
   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


Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

QUICK FIX: I do not like this solution


C#:
using System;
using System.Linq;
 
public partial class MLDefault : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
 
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        var list = new[]{
                new{
                    Description = "Text1"
                },
                new{
                    Description = "Text2"
                }
            };
 
        var lSearch = list.Where(i => i.Description.ToLower().Contains(txtText.Text.ToLower()));
 
        rgGrid.DataSource = lSearch;
        rgGrid.DataBind();
    }
}


ASP.NET

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MLDefault" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
 
    <script type="text/javascript">
        function OpenWindow() {
            $find('<%= rwGrid.ClientID %>').show();
            $get('<%= btnSearch.ClientID %>').click();
        }
    </script>
 
    <telerik:RadScriptManager ID="ScriptManager" runat="server" />
    <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="btnSearch">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgGrid" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <input type="button" value="Open & Search" onclick="javascript:OpenWindow();" />
    <asp:TextBox ID="txtText" runat="server" />
    <telerik:RadWindowManager ID="RadWindowManager" runat="server" EnableShadow="True"
        Behaviors="None" InitialBehaviors="None" ShowContentDuringLoad="False" VisibleStatusbar="False"
        Modal="true" RestrictionZoneID="aspnetForm">
        <Windows>
            <telerik:RadWindow ID="rwGrid" runat="server" Behaviors="Close,Move">
                <ContentTemplate>
                    <asp:Button ID="btnSearch" runat="server" Text="Search Server" OnClick="btnSearch_Click"
                        Style="display: none; visibility: hidden;" />
                    <telerik:RadGrid ID="rgGrid" runat="server" AutoGenerateColumns="False" CellSpacing="0"
                        GridLines="None">
                        <MasterTableView AllowSorting="False">
                            <NoRecordsTemplate>
                                <div>
                                    Empty</div>
                            </NoRecordsTemplate>
                            <Columns>
                                <telerik:GridBoundColumn DataField="Description" />
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                </ContentTemplate>
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
    </form>
</body>
</html>


Thanks anyway...

Tags
Window
Asked by
David
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David
Top achievements
Rank 1
Share this question
or