Ajax not working on first click

3 posts, 1 answers
  1. Bill Wolff
    Bill Wolff avatar
    10 posts
    Member since:
    Jul 2006

    Posted 14 Jan 2015 Link to this post

    I have a number of forms and grids that use RadAjaxManager to setup AJAX settings. This works well after the first click. That first clicks always does a full page refresh which is slow and does not show the RadAjaxLoadingPanel graphic. Is there a way to force the page to register the controls correctly so any click is handled correctly by RadAjaxManager?

    The controls are placed in web parts that appear in SharePoint pages.
  2. Answer
    Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 16 Jan 2015 Link to this post

    Hi,

    Thank you for contacting us and for your question.

    Note that ajaxifying the telerik controls that are positioned within a user controls works somewhat differently from the scenario when they are loaded directly on a web form. In you case, you need to move the RadAjaxManager control to the web part class, create it there and add it to the Controls collection of the web part as follows:

    private RadAjaxManager _ajaxManager;
     
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
     
        SetUpAjaxManagerOnPage();
     
        EnsureChildControls();
    }
     
     
    protected void SetUpAjaxManagerOnPage()
    {
        RadAjaxManager currentAjaxManager = RadAjaxManager.GetCurrent(Page);
     
        if (currentAjaxManager == null)
        {
            Page.Form.Controls.AddAt(0, AjaxManager);
            Page.Items.Add(typeof(RadAjaxManager), AjaxManager);
        }
    }
     
    protected virtual RadAjaxManager AjaxManager
    {
        get
        {
            if (_ajaxManager == null)
            {
                _ajaxManager = RadAjaxManager.GetCurrent(Page);
     
                if (_ajaxManager == null)
                {
                    _ajaxManager = new RadAjaxManager() { ID = "RadAjaxManager1" };
                }
            }
     
            return _ajaxManager;
        }
    }


    Then in the OnLoad event of the web part, get the RadAjaxManager as follows:
    RadAjaxManager _manager = RadAjaxManager.GetCurrent(Page);

    and add your ajax settings programmatically. Beforehand, you should have the user control in the CreateChildControls method of the web part and there through FindControl you should retrieve the controls to ajaxify. Keep them in a private variable local to the web part class and use that in the OnLoad event to dynamically add the ajax settings.


    Hope this information will prove helpful.

    Regards,
    Maria Ilieva
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bill Wolff
    Bill Wolff avatar
    10 posts
    Member since:
    Jul 2006

    Posted 22 Jan 2015 in reply to Maria Ilieva Link to this post

    This was helpful. I did not create the RadAjaxManager in code. Instead, it was added to the Master page that is shared by all pages in this application along with some JavaScript needed in the OnRequest event. I then use RadAjaxManager.GetCurrent(Page) in each web part to point to this manager.

    Creating the AjaxSettings in code in the OnLoad event of each web part solved the timing issues and AJAX now works first click every click.
Back to Top