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

Ajaxified control still does postback when updated the first time

1 Answer 45 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 11 Jan 2013, 03:25 PM
Hi,

I have this scenario:
Two controls (say controlA and controlB), both contain some RadButtons. If a click occurs in controlA, it should update controlB and vice versa. But only case 1 works, case 2 doesn't work correctly.

This is my code:
protected override void OnPreRender(EventArgs e)
      {
         base.OnPreRender(e);
 
         RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
         manager.AjaxSettings.AddAjaxSetting(controlA, controlB, loadingPanel);
         manager.AjaxSettings.AddAjaxSetting(controlB, controlA, loadingPanel);
      }

The second case only works after one click, e.g. the second, third, ... click works correctly and the loading panel will be displayed.
Both controls don't have any conditional controls, all buttons are added in CreateChildControl. EnsureChildControls is called in OnLoad of both controls.

Which of the controls might be erroneous in this case? The control which does the trigger or the control which is updated?

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 15 Jan 2013, 11:25 AM
Hello Jan,

In case you are using WebParts please ensure that you create the RadAjaxManager 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;
    }
}

Also please try to place the RadAjaxSettings in the OnLoad event instead of OnPreRender and verify if this helps.

Kind regards,
Maria Ilieva
the Telerik team
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 their blog feed now.
Tags
Ajax
Asked by
JP
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or