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

Ajax not working on first click

2 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill Wolff
Top achievements
Rank 1
Bill Wolff asked on 14 Jan 2015, 09:41 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Maria Ilieva
Telerik team
answered on 16 Jan 2015, 07:59 AM
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.

 
0
Bill Wolff
Top achievements
Rank 1
answered on 22 Jan 2015, 09:36 PM
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.
Tags
Grid
Asked by
Bill Wolff
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Bill Wolff
Top achievements
Rank 1
Share this question
or