Need help updating a RadGrid programmatically with ajax

6 posts, 0 answers
  1. Adam
    Adam avatar
    3 posts
    Member since:
    Dec 2011

    Posted 20 Jan 2014 Link to this post

    • Rad ASP.NET Ajax Controls Version: 2013.2.717.40
    • ASP.NET Version: 4.0.30319
    • .NET 4.0
    • Browser: IE 10

    Issue: I'm trying to programmatically add ajax settings so that a asp:button click updates a RadGrid on a User Control.  The reason that this is being done programmatically is because the User Control is only visible to specific users, and an error was occurring when a user that the Control wasn't visible on used the page.

    What is happening, is I get the loading pannel spinner appearing over the button and RadGrid area, but no data.  If there is a postback the data shows, or if you manually click the refresh button the data shows on the Grid.  

    The code pieces in question, there is a site master with the ajaxmanager, and a proxymanager on the user control and the page.  The page checks if the user is an Admin then calls a function to set the user control to visible and does a few small things and registers the button with the grid and loading panel to the UserControl's proxymanager.  Here are the snippets of the ajax C# and the grid.

    Site.MasterPage
    <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="Buttons" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1" Skin="Default" />

    UserControl.ascx
    <div style="padding: 0px; border: solid 1px #000; border-top: none;">
                <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_OnNeedDataSource"
                    GridLines="None" ShowStatusBar="true" AllowPaging="true" PageSize="15" AllowSorting="true"
                    style="min-width:925px">
                    <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                    <MasterTableView AutoGenerateColumns="false" CommandItemDisplay="Top" TableLayout="Fixed">
                        <CommandItemSettings ShowAddNewRecordButton="false" ShowExportToCsvButton="false"
                            ShowExportToExcelButton="false" ShowExportToPdfButton="false" ShowExportToWordButton="false"
                            ShowRefreshButton="true" />
                        <Columns>
                            <telerik:GridBoundColumn UniqueName="Date" DataField="Date" HeaderText="Date" Groupable="false" />
                            <telerik:GridBoundColumn UniqueName="Guid" DataField="Guid" HeaderText="Guid" Groupable="false" />
                            <telerik:GridBoundColumn UniqueName="Name" DataField="Name" HeaderText="Name" Groupable="false" />
                            <telerik:GridBoundColumn UniqueName="Value" DataField="Value" HeaderText="Value"
                                Groupable="false" />
                        </Columns>
                    </MasterTableView>
                    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
                </telerik:RadGrid>
            </div>
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
            <AjaxSettings>
           </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default" />

    Default.cs for the page that is being loaded.
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                       if (User.IsInRole("Admin"))
                       {
                                LoadDebugInfo();
                                DebugInfoDisp.RegisterRadGrid();
                                DebugInfoDisp.RadAjaxProxy.AjaxSettings.AddAjaxSetting(button, DebugInfoDisp.RadAjaxLoadingPanel);
                                DebugInfoDisp.RadAjaxProxy.AjaxSettings.AddAjaxSetting(button, DebugInfoDisp.RadAjaxGrid);                   
                        }
                }
    }

    I'm still learning to use the ajax controls, I'm not sure what I have wrong.  The doc's I have used to get to this point are:
    http://www.telerik.com/help/aspnet-ajax/ajax-control-not-updated.html
    http://www.telerik.com/help/aspnet-ajax/ajax-add-ajaxsettings-programmatically.html


  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 22 Jan 2014 Link to this post

    Hi Adam,

    The proper approach for achieving the required functionality is to access the RadGrid control from the UserControl and add programmatic settings directly to the main RadAjaxManager control as described in the help topic below:
    http://www.telerik.com/help/aspnet-ajax/ajax-user-controls.html

    The code should look similar to the one bellow:
    protected void Page_Load(object sender, EventArgs e)
    {
        //Get the WebUserControl
        UserControl MyControl = (UserControl)Page.FindControl("WebUserControl1");
      
        //Get user control'sRadGrid control
        RadGrid grd = (RadGrid)MyControl.FindControl("RadGrid1");
      
        //Add the necessary AJAX setting programmatically
        RadAjaxManager1.AjaxSettings.AddAjaxSetting(button, grd);
    }

    Give this a try and let me know if it helps.

    Regards,
    Maria Ilieva
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Adam
    Adam avatar
    3 posts
    Member since:
    Dec 2011

    Posted 22 Jan 2014 Link to this post

    Hello,

    I tried that and the data does not load in radgrid1 when the button is clicked.  I added a reference to the loadingpanel on the page and when its clicked the loading pannel spins above the control but still no data is loaded.

    protected void Page_Load(object sender, EventArgs e)
    {
        //Get the WebUserControl
        UserControl ctrl = FindControlRecursive(this, "DebugInfoDisp") as UserControl;
     
        //Get user control'sRadGrid control
        RadGrid grd = (RadGrid)ctrl.FindControl("RadGrid1");
     
        RadAjaxManager1.AjaxSettings.AddAjaxSetting(button, grd,RadAjaxLoadingPanel1);
    }
     
    private Control FindControlRecursive(Control root, string id)
    {
        if (root.ID == id) return root;
        foreach (Control c in root.Controls)
        {
            Control t = FindControlRecursive(c, id);
            if (t != null)
                return t;
        }
       return null;
    }
  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 27 Jan 2014 Link to this post

    Hi Adam,

    Could you please elaborate  bit more on what logic exactly is excited on the button click event. Are you calling RadGrid1.Rebind() after the server logic you are implementing?
    It would be best if you could send us runnable version of your application in the support ticket you have opened. Thus we will be able to test it locally and do our best to isolate the root cause ft he issue in a timely manner.

    Regards,
    Maria Ilieva
    Telerik
    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 UI for ASP.NET AJAX, subscribe to the blog feed now.
  6. Adam
    Adam avatar
    3 posts
    Member since:
    Dec 2011

    Posted 03 Mar 2014 Link to this post

    To follow up for anyone else having this issue.

    The problem was registering the RadAjaxProxy with the radgrid in the !IsPostBack.  Moving the code into the Page_Load resolved the issue.
  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 06 Mar 2014 Link to this post

    Hello Adam,

    Thank you for sharing the solution for this issue. I'm sure it will be of a big help for other users facing the same problem.
    Generally the programmatic ajax setting should always be unconditionally added in a Page event handler, which is executed each time during the page lifecycle (Page_Load, Page_PreRender) so that the control could be properly ajaxified.

    Regards,
    Maria Ilieva
    Telerik

    DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017