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

Grid null in Sys.Application.Load

2 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
towpse
Top achievements
Rank 2
towpse asked on 26 Jan 2009, 02:36 PM
Hey all.
I'm trying to convert a page to do data binding all on the client-side.
I'm starting with a simple method call from javascript in the aspx file.

    <script language="javascript" type="text/javascript">
        function pageLoad() {
            load();
        }
    </script>

In my javascript file I'm using

Sys.Application.add_load(function() {
 _tableView = $find('MyGridId').get_masterTableView();
}

In which case the grid is null or not an object. Sys.Application.load is raised after all scripts have been loaded and the objects in the application have been created and initialized so I would expect the grid to be there.

What am I missing?

Here's my grid. Thanks.
                <telerik:RadGrid runat="server" ID="MyGridId" Skin="Office2007" AutoGenerateColumns="false" AllowMultiRowSelection="true" 
                    Width="600" > 
                    <MasterTableView  runat="server" ClientDataKeyNames="Id, PointId" HeaderStyle-HorizontalAlign="Center" TableLayout="Fixed"  > 
                        <NoRecordsTemplate> 
                            <asp:Localize ID="Localize2" runat="server" Text="<%$ Resources:Resource, NO_ALARMS_CONFIGURED %>" /></NoRecordsTemplate
                        <Columns> 
                            <telerik:GridBoundColumn UniqueName="Display" DataField="Display" HeaderText="<%$ Resources:Resource, DISPLAY%>" /> 
                            <telerik:GridTemplateColumn  UniqueName="DisplayOnBoard" HeaderText="<%$ Resources:Resource, DISPLAY_ON_BOARD %>"
                                <ItemTemplate> 
                                    <asp:Label ID="Label1" runat="server"><%# (bool)Eval("DisplayOnBoard") ? "Yes" : "No"%></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn UniqueName="NotifyWhenOn" DataField="NotifyWhenOn" HeaderText="<%$ Resources:Resource, NOTIFY_ON_ACTIVE %>"
                                <ItemTemplate> 
                                    <asp:Label ID="Label2" runat="server"><%# (bool)Eval("NotifyWhenOn") ? "Yes" : "No"%></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn UniqueName="NotifyWhenOff" DataField="NotifyWhenOff" HeaderText="<%$ Resources:Resource, NOTIFY_ON_RETURN %>"
                                <ItemTemplate> 
                                    <asp:Label ID="Label3" runat="server"><%# (bool)Eval("NotifyWhenOff") ? "Yes" : "No"%></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                        </Columns> 
                    </MasterTableView> 
                    <ClientSettings> 
                        <Scrolling UseStaticHeaders="true"  AllowScroll="true" ScrollHeight="175" FrozenColumnsCount="4" /> 
                        <Selecting AllowRowSelect="true" /> 
                        <ClientEvents OnRowSelected="RowSelected" /? 
                    </ClientSettings> 
                </telerik:RadGrid> 






2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 27 Jan 2009, 08:47 AM
Hello Matt,

If you are not binding RadGrid initially on server you need to attached handler on OnCommand client event of RadGrid.

/for example/
<telerik:RadGrid runat="server" ID="RadGrid1" > 
            <MasterTableView AutoGenerateColumns="False">                                          
                <Columns> 
                   //grid columns  
                </Columns> 
            </MasterTableView>    
            <ClientSettings> 
                <ClientEvents OnCommand="function(){}" /> 
            </ClientSettings>            
        </telerik:RadGrid> 


Thus RadGrid will expect that it will bound to client and MasterTableView will be created.

All the best,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
towpse
Top achievements
Rank 2
answered on 03 Feb 2009, 04:33 PM
Right, right. Thanks.
Or you can bind to an empty collection of some kind on the server side.
                Grid.DataSource = new object[] { };
                Grid.DataBind();
Tags
Grid
Asked by
towpse
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
towpse
Top achievements
Rank 2
Share this question
or