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

RaisePostBackEvent and RadDock_Command

2 Answers 125 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 2
Sean asked on 18 Jul 2011, 08:14 PM
Hi Telerik,

Is it possible to have a RadDock class which implements IPostBackEventHandler's RaisePostBackEvent method and also utilize the cleanliness of RadDock_Command?

Currently, I have this setup:

/// <summary>
/// Parses custom/default commands of RadDock.
/// </summary>
public void RadDock_Command(object sender, DockCommandEventArgs e)
{
    Logger.InfoFormat("Command {0} detected for {1} ", e.Command.Name, ID);
 
    switch (e.Command.Name)
    {
        case "Close":
            Close();
            break;
        case "Refresh":
            RefreshContent(ForceCacheRefresh.True);
            break;
        case "Toggle Legend":
            ToggleLegend();
            break;
        case "Undo Drill Down":
            UndoDrillDown();
            break;
        default:
            Logger.ErrorFormat("Unhandled command name: {0}", e.Command.Name);
            break;
    }
}

public void RaisePostBackEvent(string eventArgument)
{
 
    HandleDialogClose(eventArgument);
}
 
private void HandleDialogClose(string json)
{
    if (json.Contains("HistoricalLocalSettingsJSON"))
    {
        UpdateSettings(JsonConvert.DeserializeObject<HistoricalLocalSettingsJSON>(json));
    }
    else if (json.Contains("CustomLocalSettingsJSON"))
    {
        UpdateSettings(JsonConvert.DeserializeObject<CustomLocalSettingsJSON>(json));
    }
    else
    {
        Logger.ErrorFormat("Unable to handle JSON: {0}", json);
    }
}

My RadDock has a custom command which opens a dialog window. This window visualizes some of the RadDock's settings. After closing, those changes must be persisted and reflected on the RadDock.

I noticed, however, that after implemented IPostBackEventHandler, that RadDock's commands are getting eaten by this RaisePostBackEvent instead of filtering into RadDock_Command.

Is it possible to achieve this?

2 Answers, 1 is accepted

Sort by
0
Accepted
Pero
Telerik team
answered on 21 Jul 2011, 01:06 PM
Hi Sean,

The RadDock already implements the IPostBackEventHandler interface, and when you implement it in your local class, the RadDock's implementation gets overridden. Unfortunately there is no suitable method that you can override to implement your custom logic, and keep the RadDock's command event. I will introduce a protected virtual method that is called when the IPostBackEventHandler.RaisePostBackEvent is called, so it can be modified in the inherited classes.

For the time being please call the following method after your code in your IPostBackEventHandler.RaisePostBackEvent method:

protected virtual void RaisePostBackEvent(string eventArgument)
{
    if (eventArgument.ToLower() == "dockpositionchanged")
    {
        //The postback was initiated by drag-dropping the dock control.
        // We will fire the DockPositionChanged event automatically
        // if the client state was modified.
        return;
    }
 
    if (Commands.Count == 0)
    {
        if ((DefaultCommands & DefaultCommands.Close) > 0)
            Commands.Add(new DockCloseCommand());
        if ((DefaultCommands & DefaultCommands.ExpandCollapse) > 0)
            Commands.Add(new DockExpandCollapseCommand());
        if ((DefaultCommands & DefaultCommands.PinUnpin) > 0)
            Commands.Add(new DockPinUnpinCommand());
    }
    DockCommand command = Commands.Find(delegate(DockCommand cmd)
    {
        return cmd.Name == eventArgument;
    });
 
    if (command != null)
    {
        OnCommand(new DockCommandEventArgs(command));
    }
}


All the best,
Pero
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Sean
Top achievements
Rank 2
answered on 21 Jul 2011, 06:10 PM
Hey Pero,

Thanks for that change. That would be cool to see in the future. 

I am not entirely sure what your code is referencing. This is what worked for me:

/// <summary>
/// Fires in multiple cases:
///    -- Whenever a user clicks a command on the titlebar of the dock.
///    -- Whenever a user closes a dialog window related to the dock (*LocalSettings)
/// </summary>
/// <param name="eventArgument">Empty if its a titlebar command, else json representing settings</param>
public void RaisePostBackEvent(string eventArgument)
{
    switch (eventArgument)
    {
        case "Close":
            Close();
            break;
        case "Refresh":
            RefreshContent(ForceCacheRefresh.True);
            break;
        case "Toggle Legend":
            ToggleLegend();
            break;
        case "Undo Drill Down":
            UndoDrillDown();
            break;
        default:
            HandleDialogClose(eventArgument);
            break;
    }
}

The cases are all the same as they would be in the Command event. Then I use the default to pass off more complex work. 

:) Thanks for looking at this though.
Tags
Dock
Asked by
Sean
Top achievements
Rank 2
Answers by
Pero
Telerik team
Sean
Top achievements
Rank 2
Share this question
or