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

'null' is null or not an object RadGrid within UserControl

1 Answer 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kunal
Top achievements
Rank 1
Kunal asked on 11 Jan 2011, 07:52 AM
Hi,

I am using RadGrid within a usercontrol sitting inside a SharePoint webpart. All my other functionalitites are working fine, but I am having issues when once I scroll through couple of pages in the grid and then try to hit filter button I get an error 'null' is null or not an object. Below is my RadGrid within a user control, any help will be greatly appreciated as I don't want to give a buggy UI to my clients:

 

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
  
        <script type="text/javascript">
            function GetSelectedItems() {
                alert($find("<%= grdAllContacts.MasterTableView.ClientID %>").get_selectedItems().length);
            }
        </script>
  
    </telerik:RadCodeBlock>
  
<br />
<!-- content start -->
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
                <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="grdAllContacts" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>      
                    <telerik:AjaxSetting AjaxControlID="grdAllContacts">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="grdAllContacts" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <asp:Button ID="Button2" CssClass="button" Text="Get Selected Items Count" OnClientClick="GetSelectedItems(); return false;" runat="server" />
<br />
            <telerik:RadGrid ID="grdAllContacts" Width="97%" 
             AllowPaging="True" PageSize="20" runat="server" ShowGroupPanel="false"
             OnNeedDataSource="grdAllContacts_NeedDataSource" GridLines="None"  AutoGenerateColumns="false" AllowMultiRowSelection="true">
                
              <PagerStyle Mode="NextPrev" />                
              <GroupHeaderItemStyle BorderColor="Black" Font-Bold="true"></GroupHeaderItemStyle>
  
                 <MasterTableView Width="100%" GroupLoadMode="Server" TableLayout="Fixed" AllowPaging="True" PageSize="20" AllowFilteringByColumn="true">
                <GroupByExpressions>
                    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField FieldAlias="FamilyName" FieldName="FamilyName"></telerik:GridGroupByField>
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="FamilyName"></telerik:GridGroupByField>
                        </GroupByFields>
                    </telerik:GridGroupByExpression>
                </GroupByExpressions>
                 <Columns>
                 
                         <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" />
  
                    <telerik:GridBoundColumn SortExpression="FamilyName" HeaderText="Family Name" HeaderButtonType="TextButton"
                        DataField="FamilyName" HeaderStyle-HorizontalAlign="Center" Visible="false" AutoPostBackOnFilter="true">
                         <HeaderStyle Width="15%" />
                    </telerik:GridBoundColumn>
                     
                    <telerik:GridBoundColumn SortExpression="Context" HeaderText="Contact Type" HeaderButtonType="TextButton"
                        DataField="Context">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="OrganisationName" HeaderText="Organisation Name" HeaderButtonType="TextButton"
                        DataField="OrganisationName" >
                        <HeaderStyle Width="32%" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="RoleTitle" HeaderText="Role Title" HeaderButtonType="TextButton"
                        DataField="RoleTitle" >
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="Phone" HeaderText="Phone"
                        HeaderButtonType="TextButton" DataField="Phone" >
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="Mobile" HeaderText="Mobile"
                        HeaderButtonType="TextButton" DataField="Mobile">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="Fax" HeaderText="Fax"  AutoPostBackOnFilter="true" 
                        HeaderButtonType="TextButton" DataField="Fax">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="ID" HeaderText="ID"
                        HeaderButtonType="TextButton" DataField="ID" Visible="false">
                    </telerik:GridBoundColumn>
                </Columns>
                  
            </MasterTableView>
            <ClientSettings AllowGroupExpandCollapse="True" ReorderColumnsOnClient="false" AllowDragToGroup="false" 
                AllowColumnsReorder="false" EnableRowHoverStyle="false">
                <Selecting AllowRowSelect="True" />
                  
            </ClientSettings>
              
            </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Kunal
Top achievements
Rank 1
answered on 12 Jan 2011, 12:52 AM
Ok, I ahve found the solution. Since I was using this in SharePoint 2010 which already had scriptmanager in master page I don't necessarily from choice have to use RadScriptManager. So I removed: following piece of code from my user control:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"
                <AjaxSettings
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"
                        <UpdatedControls
                            <telerik:AjaxUpdatedControl ControlID="grdAllContacts" /> 
                        </UpdatedControls
                    </telerik:AjaxSetting>       
                    <telerik:AjaxSetting AjaxControlID="grdAllContacts"
                        <UpdatedControls
                            <telerik:AjaxUpdatedControl ControlID="grdAllContacts" /> 
                        </UpdatedControls
                    </telerik:AjaxSetting
                </AjaxSettings
            </telerik:RadAjaxManager

The draw back of not using RadScriptManager is that postback happens on paging, so there is no ajax experience. Telerik gurus, please confirm if this is the correct assumption. Also, it will be great to know how we can use RadScriptManager within a SharePoint UserControl sitting inside a webpart.
Tags
Grid
Asked by
Kunal
Top achievements
Rank 1
Answers by
Kunal
Top achievements
Rank 1
Share this question
or