Elegance or Silliness? Opinions wanted

2 posts, 0 answers
  1. TonyG
    TonyG avatar
    239 posts
    Member since:
    Feb 2006

    Posted 26 Jul 2010 Link to this post

    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!
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 29 Jul 2010 Link to this post

    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
Back to Top