Loading...

Last updated: Oct 24 2016

Area: Episerver Commerce Applies to versions: 10 and higher
Other versions:

Working with CommandManager

CommandManager is a class for handling actions in Commerce Manager. The following command types are available:

Commands defined in XML files

Commands are defined in the View/Commands section of an XML file and look like this:

<Command id="Command_Name1">
<CommandType>Navigate</CommandType>
...
</Command>

The following example shows how to bind a command to a toolbar button simply by adding the commandName attribute with the command identifier to Button

<Button id="Button1" text="button text" commandName="Command_Name1"></Button>

Navigate

The navigate-type command can contain the following tags:

  • Url (string). URL to page for navigation.
  • Target (string). Navigate to named frame.
  • EnableHandler. Server handler in the format "className, assemblyName" defining accessibility of the command.

The server handler must implement the ICommandEnableHandler interface.

You can use the following templates as dynamic parameters for the Url parameter.

OpenWindow

The OpenWindow-type command can contain the following tags:

  • Url (string). Url to page for opening in pop-up window. You can use the same templates as in the Navigate-type command.
  • Width (int). Width in pixels for window(default, 640).
  • Height (int). Height in pixels for window(default, 480).
  • Left (int). Left position for window (show in center by default).
  • Top (int). Top position for window(show in center by default).
  • Scroll (True/False). Allow scroll bar for window or not.
  • Resize (True/False). Allow resize for window or not.
  • RefreshMethod (string). JavaScript function name with one parameter, which will be called after window close.
  • UpdatePanelIds (string). List of UpdatePanels IDs, which necessary to update after window close.
  • EnableHandler (string). Server handler in format "className, assemblyName" which define accessibility of the command.

In WEB, you do not have a standard use-case for monitoring closed pop-up windows, so you need to take additional actions. To update the parent window, run the following code:

CommandManager.RegisterRefreshParentWindowScript(this.Page, param);

The param string parameter is sent to the JavaScript function; if you do not need any parameters for the client side, send String.Empty.

Use the following code to close the current pop-up windows and refresh parent windows:

CommandManager.RegisterCloseOpenedWindowScript(this.Page, param);

For updating UpdatePanels in the parent window (which are defined in the XML description), run the following code.

The commandId command name is mapped from <Commandid=""> in the XML.

OpenFrameModalPopup

The OpenFrameModalPopup-type of command can contain these tags:

  • Url (string). URL to page for opening in pop-up window. You can use the same templates as in the Navigate-type command.
  • Width (int). Width in pixels for window (default, 640).
  • Height (int). Height in pixels for window (default, 480).
  • Left (int). Left position for window (displayed in center by default).
  • Top (int). Top position for window (displayed in center by default).
  • PopupTitle (string). Pop-up window title.
  • Drag (True/False). Allow to drag window or not (default False).
  • UpdatePanelIds (string). List of UpdatePanels IDs, which is necessary to update after the window closes.
  • EnableHandler (string). Server handler in format "className, assemblyName", which defines accessibility of the command.
  • AutoHeightResize (True/False). When True, if the pop-up dialog cannot be displayed in the browser, its height is adjusted. 

The .ascx-control, which should be displayed in dialog, must implement the IModalPopupControl interface:

To update the parent window and close the ModalPopup, run the following code:

CommandParameters cp = new CommandParameters(commandId);
CommandManager.RegisterCloseOpenedFrameScript(this.Page, cp.ToString());

If the parent window contains UpdatePanels, and you need to run a full update for the window when the button id="Btn1" is pressed, run the following code in Page_Load for the .ascx control:

ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(Btn1);

For closingModalPopup:

CancelButton.OnClientClick =
CommandManager.GetCloseOpenedFrameScript(
this.Page, String.Empty, false, true);

If you need to run another command from ModalPopup:

CommandManager cm = CommandManager.GetCurrent(this.Page);
Dictionary<string, string> prms = new Dictionary<string, string>();
string command = cm.AddCommand(className, viewName, placeName, "MC_TimeTracking_MultipleAdd", prms);
MultipleAddLink.NavigateUrl = String.Format(
CultureInfo.InvariantCulture,
"javascript:{0};{1}", ScriptHidePopup, command);

The following steps create a dialog box for a MyPage.aspx custom page.

1. Create an .ascx control implementing the IModalPopupControl interface, and name it MyControl.ascx.
2.Create an XML file with the name MyPage.xml.

3. Run the following code for MyPage to display the dialog box:

CommandManager cm = CommandManager.GetCurrent(this.Page);
CommandParameters cp = new CommandParameters("MyCommand");
string command = cm.AddCommand("MyPage ", "", "", cp);

4. After you run the AddCommand method, the variable command contains JavaScript code. If you add the javascript: prefix, you can use the NavigateUrl property for the HyperLink control.

ServerAction

The ServerAction-type command can contain the following tags:

  • ConfirmationText (string). Text in the confirmation dialog box. If this parameter is not defined, it does not display text.
  • Handler (string). Server handler for command in format "className, assemblyName".
  • UpdatePanelIds (string). List of UpdatePanels IDs, which are necessary to update after window close.
  • EnableHandler (string). Server handler in format "className, assemblyName" which defines the accessibility of the command.

The server handler must implement the ICommand interface. The following is an example of the server handler, with actions for selected elements in the grid:

The following example shows how to get the primaryKeyId for a grid record:

ClientAction

The ClientAction-type command can contain the following tags:

  • ClientScript. String containing JavaScript, use a template like {TemplateType:KeyName} (see the Navigate section for the description).
  • EnableHandler (string). Server handler in the format "className, assemblyName" defining accessibility of the command.

Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/