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

Elegance or Silliness? Opinions wanted

1 Answer 67 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
TonyG
Top achievements
Rank 1
TonyG asked on 26 Jul 2010, 08:00 PM
There are cases where we need to set the RadAjaxManager with a lot of controls in order to get the right dynamic updates. Consider the following code:
RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(fShiftQty , fBalance , Progress1);
RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(fShiftQty , fHours , Progress1);
RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(fHours , fShiftQty , Progress1);
RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(fHours , fBalance , Progress1); RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(fCrewSize , fCrewTotal , Progress1);
RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(fCrewSize , fCrewTemps , Progress1);
RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(fCrewSize , fCrewPeople , Progress1);
RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(btnSave2 , btnSave2 , Progress1);
(RAMPUC=RadAjaxManagerProxy for UserControl)
It's basic and effective, but wordy and redundant, right? And a complex page can have a lot more of those lines. So here's an alternative:
SetAjaxUpdates( new Control[ , ] {
        {fShiftQty, fBalance},
        {fShiftQty, fHours},
        {fHours , fShiftQty},
        {fHours , fBalance} , 
        {fCrewSize , fCrewTotal} ,
        {fCrewSize , fCrewTemps} ,
        {fCrewSize , fCrewPeople },
        {btnSave2 , btnSave2}
    }
);

And here's the method:
void SetAjaxUpdates( Control[ , ] controls )
{
    for ( int i = 0 ; i <= controls.GetUpperBound(0) ; i++ )
        RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(
             controls[ i , 0 ] , controls[ i , 1 ] , Progress1);
}

Assuming that in this case I do want Progress1 to be active for all updates, from a readability perspective do other people here find the alternative preferable to the original? Or am I just adding more code where it's not necessary and abstracting/refactoring into even more complexity?

More importantly, this is what I came up with to try to streamline the code a bit, and make adding new trigger/update relationships easier, but is there a better, or more elegant way to do what I'm doing here?

Opinions?  Thanks!

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 29 Jul 2010, 12:15 PM
Hi Tony,

The solution you implemented is good enough if different controls are added in the AjaxManager settings. However in your code I note that most of the controls update each other. In such cases easyer way for adding the settings would be to wrap all this controls into one asp Panel and add those Panel in the Ajaxmnaager settings. For example:

RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(Panel1 , Panel1, Progress1);
RAMPUCScheduleEdit.AjaxSettings.AddAjaxSetting(fCrewSize, Panel2, Progress1);

Where Panel1 conatins fShiftQty, fBalance, fHours controls and Panel2 contains fCrewTotal, fCrewTemps,fCrewPeople controls.


Kind regards,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Ajax
Asked by
TonyG
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or