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

Updating different control with AJAX

15 Answers 297 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Remko
Top achievements
Rank 1
Remko asked on 26 Feb 2008, 10:48 AM
I have tried to search the forums & help files for this but not having much luck.
Coming from an 'Anthem' ajax approach my techniques need reworking due to the way that AjaxManager is working (promethius version). I am used to updating different controls depending upon server behind code choices, so I came accross the ResolveUpdatedControls event description, but unfortunately it doesn't seem to ever fire for me.
So I read the KB article '(ID#757) Updating different control with AJAX depending on clicked ToolbarButton' and tried to rework that for 'promethius', but still the event is not firing.
Is there something obvious that i might be missing that anyone can think of?
I have a test app, but see no way to upload it here.

Thanks,
Kevin.

15 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 28 Feb 2008, 02:35 PM
Hi Kevin,

The ResolveUpdatedControls is no more for Prometheus. It was created initially to serve as a workaround for scenarios where the initiator is being disposed from the page, but this is never the case in Prometheus due to the fact that all controls in the AjaxSettings are nested in UpdatePanels.
Our own ajax technology works in completely different way and that is why altering the AjaxSettings in runtime is possible. For Prometheus however, this cannot be implemented due to the way MS AJAX operates.
If this is important for you, using our Ajax is still an option.

Regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Remko
Top achievements
Rank 1
answered on 28 Feb 2008, 02:59 PM
ok, so the event will dissapear from the Ajax Manager control in the next version?
Does this mean that I will not be able to update say 1 of a possible number of controls depending upon a callback, but have to update all each time by setting the ajax manager configuration? or am i missing something here?
Thanks,
Kevin.
0
Accepted
Steve
Telerik team
answered on 28 Feb 2008, 03:04 PM
Hello Kevin,

Yes the ResolveUpdatedControls will be removed for the official release. The AjaxSettings contain multiple control relations and defining a control to update certain number of controls will mean they will all be updated on request from this control (if this is what you are asking). If you do not want that, you can use the AjaxSettingCreating event and cancel the creating of the settings.

Best wishes,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark Griebling
Top achievements
Rank 1
answered on 29 Feb 2008, 05:31 PM
Steve,

Thanks!!  I have been converting a classic RadAjax application and encountered Sys.InvalidOperationException script errors using the old approach.  Cancelling in the AjaxSettingCreating event works as I need it to.

I suggest expanding on this in the Migration notes.  I was adding all updated controls in the AjaxRequent event handler and never used the ResolveUpdatedControls event.  So I never made the connection between my errors and the AjaxSettingCreating event.

Thanks again,
Mark
0
Jacky Chau
Top achievements
Rank 1
answered on 26 Mar 2008, 03:24 PM
So what is the final solution to this problem?  I am facing the same problem as OP where I need to update certain controls based on some criteria.  I have a button A, a checkbox B, and two panels C and D.  When button A is clicked, depending on the state of checkbox B, either panel C or D will be updated.  The old way of doing this before was to add an AjaxSetting for buttonA --> buttonA just to get it to do an ajax callback.  Then on the buttonA's click event, a conditional statement determines which panel to update and that panel is added to the RadAjaxManager's controlstoupdate collection in ResolveUpdatedControls event.  How can I accomplish the same scenario now?  An example would be highly appreciated.
0
Mark Griebling
Top achievements
Rank 1
answered on 26 Mar 2008, 03:37 PM
If I understand correctly, create an AjaxSetting in the designer on Button A for both Panel C and Panel D.

Next, override the AjaxSettingCreating event.  In that, have logic to cancel the create when for the setting when you don't want to update it.  Here is my override:
protected void rajmMain_AjaxSettingCreating(object sender, Telerik.Web.UI.AjaxSettingCreatingEventArgs e)  
{  
if (IsPostBack)  
     if (!UpdatedControls.Contains(e.Updated));  
           e.Canceled = true;  

Updated controls is a private variable.  In the same place I previously dynamically created the AjaxSetting, I now add the control to UpdatedControls.
0
Jacky Chau
Top achievements
Rank 1
answered on 26 Mar 2008, 03:53 PM
Thanks Mark for the quickest reply ever.  I already tried catching the AjaxSettingCreating event and cancelling the ajax settiing base on some condition.  However, it has a nasty side effect of remembering that I cancelled the ajax setting so if I click the button again, it will do a regular postback instead of ajax callback. 
0
Mark Griebling
Top achievements
Rank 1
answered on 26 Mar 2008, 04:11 PM
For other reasons I am creating all my AjaxSettings in the Page_Load event.  That seems to get around the issue for me.  Of course, there are a lot of things I am doing different, so that may not help either.  
0
Jacky Chau
Top achievements
Rank 1
answered on 26 Mar 2008, 04:12 PM
I fixed the issue by making the button always update a new empty panel.  This seems to work fine but the old way is definitely better.  There are complex scenarios where I do not know ahead of time, all the ajax settings I need to create. 
0
Mark Griebling
Top achievements
Rank 1
answered on 26 Mar 2008, 04:26 PM
On the subject of crazy workarounds: at one point I had it working the old way by creating a dummy AjaxSetting on a Menu Seperator containing an UpdatedControls collect with all controls that could possibly be updated.  When I did this, my dynamically created AjaxSettings would then work.  This seemed like a solution taking advantage of some internal processing that could NOT be expected to work with future releases.  For that reason I abandoned it and used the AjaxSettingCreating solution instead.
0
Steve
Telerik team
answered on 26 Mar 2008, 04:50 PM
Hi guys,

I'm posting another solution here, that is much closer to the way the old Classic Ajax works. By clearing the triggers for the respective UpdatePanels, you get the same effect as if you've had cleared the UpdatedControls collection. Sample page is attached.

Regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark Griebling
Top achievements
Rank 1
answered on 27 Mar 2008, 12:38 AM
Steve,

In my case, I am recreating the AjaxSettings dynamically in the Page_Load, so it appears using e.Canceled = true; in the handler works.  However, the size of response is smaller.

Are there other reasons that would make clearing the trigger preferable?

In my scenario where the request is done using the client AjaxRequest method, Triggers.Clear() has no effect on response size vs doing nothing.

Mark 
0
Steve
Telerik team
answered on 27 Mar 2008, 01:58 PM
Hi Mark,

Can you show how you implement the cancellation mechanism for the scenario that Jacky tries to accomplish. I've just tried it and it is not working due to the fact that the initially not updated Panel is simply not created. Pages are attached.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark Griebling
Top achievements
Rank 1
answered on 27 Mar 2008, 10:33 PM
I think the problem you had is that you are canceling the initial creation.  I get around this by only executing the cancel mechanism on Postback

I also use a different mechanism for keeping track of the controls to update, but that should be a factor.

Here is my code behind. 
public partial class PanelCancel : System.Web.UI.Page  
{  
    List<Control> _updatedControls = new List<Control>();  
    protected void Page_Load(object sender, EventArgs e)  
    {  
 
    }  
    protected void Button2_Click(object sender, EventArgs e)  
    {  
        Label1.Text = "Panel1 Label Updated at:" + DateTime.Now.ToString();  
        Label2.Text = "Panel2 Label Updated at:" + DateTime.Now.ToString();  
 
        if (CheckBox1.Checked)  
            _updatedControls.Add(Panel1);  
        else  
            _updatedControls.Add(Panel2);  
    }  
    protected void RadAjaxManager1_AjaxSettingCreating(object sender, Telerik.Web.UI.AjaxSettingCreatingEventArgs e)  
    {  
        if (IsPostBack)  
            if (!_updatedControls.Contains(e.Updated))  
                e.Canceled = true;  
    }  
}  
 

I've also used this with dynamically created AjaxSettings and client-side AjaxRequest.

EDIT:
This strategy only appears to work well in limited scenarios.  It is good where AjaxManager is initiating requests through the client AjaxRequest or a single control initiating requests like the sample.  In scenarios where many different controls are initiating updates, there is the side effect that Jacky noted earlier in this thread (march 26).

Mark
0
Steve
Telerik team
answered on 31 Mar 2008, 01:36 PM
Hi Mark,

Thank you for sharing your approach with the community. Indeed your suggestion works correctly and might be used as a solution as well for a number of scenarios I guess. Handling the AjaxSettingCreated should not expose the "side effect" you've encountered, as the updatePanels are there, they are simply stripped off from any triggers.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Ajax
Asked by
Remko
Top achievements
Rank 1
Answers by
Steve
Telerik team
Remko
Top achievements
Rank 1
Mark Griebling
Top achievements
Rank 1
Jacky Chau
Top achievements
Rank 1
Share this question
or