Grid null in Sys.Application.Load

3 posts, 1 answers
  1. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 26 Jan 2009 Link to this post

    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. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 27 Jan 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. towpse
    towpse avatar
    224 posts
    Member since:
    Mar 2008

    Posted 03 Feb 2009 Link to this post

    Right, right. Thanks.
    Or you can bind to an empty collection of some kind on the server side.
                    Grid.DataSource = new object[] { };
                    Grid.DataBind();
Back to Top