Passing Parameters to Pages

Dynamics AX 2009

When a user performs an action that opens a different page in Enterprise Portal, it is common to use the URL to pass parameter values to the page being opened. The page that is opened can retrieve parameters from the URL and respond appropriately.

Typically, a Web menu item defined in the AOT is used to open a page in Enterprise Portal. Each Web menu item has a Parameters property that enables you to set the parameter values to be passed to the page being opened through the URL. The value for the Parameters property must comply with the standard used for passing parameters through a URL. Each parameter must have the following form:

name=value

If multiple parameters are to be passed, they must be separated by an ampersand character:

mode=2&category=1

The code for User Controls can retrieve the parameters passed through the URL. To retrieve the parameters, the code must examine the QueryString from the HTTP request. The following example shows how the parameter named "mode" is retrieved from the URL.

string mode_value;
mode_value = this.Page.Request.QueryString.Get("mode");

A common use for URL parameters in Enterprise Portal is to specify the mode for an AxForm component of a User Control. The mode of the form can be changed in code based on the "mode" parameter passed through the URL. This allows for one User Control to be used in Web parts that perform different actions, such as creating a new record or editing an existing record.

Passing the Parameter

The EPFormAction enumeration is available in the proxy for Enterprise Portal to define the modes that a form can have. The following table lists the values for the enumeration.

Enumeration value

Value

InfoMode

0

EditMode

1

CreateMode

2

ListMode

3

DeleteMode

4

NoteNote

To use this enumeration in your code, you must have a reference to the proxy for Microsoft Dynamics AX. For more information about how to create a reference to a proxy, see Proxies.


Web menu items on a toolbar are typically used to open the page that will perform actions. The Parameters property for each Web menu item is set to specify the mode the AxForm component of the user control will be set to. For example, the Web menu item that opens a page which performs an edit action will have its Parameters property set to the following:

mode=1

Retrieving the Parameter

The following function is added to the code for the User Control to retrieve the value of the mode parameter.

private EPFormAction FormMode
{
    get
    {
        // Retrieve the "mode" parameter from the query string for the page.
        queryString = this.Page.Request.QueryString.Get("mode");
        return (EPFormAction)Convert.ToInt16(queryString);
    }
}

Using the parameter

The FormMode() private function defined earlier in this topic is called in the Page_Load method for the User Control. After the mode has been retrieved, it is used to set the characteristics of the AxForm component of the User Control.

protected void Page_Load(object sender, EventArgs e)
{
    AxBoundField VehicleNumField;

    switch (this.FormMode)
    {
        case EPFormAction.EditMode:
            // Set the page title.
            this.PageDefinition.pageTitle = "Edit vehicle";

            // Set the mode for the AxForm.
            this.VehicleForm.DefaultMode = DetailsViewMode.Edit;
            this.VehicleForm.AutoGenerateEditButton = true;

            // Make the Vehicle Number field read-only.
            VehicleNumField = GetField(this.Properties.DataControlFieldCollection, "VehicleNum");
            VehicleNumField.ReadOnly = true;
            break;
        case EPFormAction.CreateMode:
            // Set the page title.
            this.PageDefinition.pageTitle = "Add vehicle";

            // Set the mode for the AxForm.
            this.VehicleForm.DefaultMode = DetailsViewMode.Insert;
            this.VehicleForm.AutoGenerateInsertButton = true;
            break;
        default:
            // Set the AxForm to read-only.
            this.VehicleForm.DefaultMode = DetailsViewMode.ReadOnly;
            break;
        }
    }
}

Community Additions

ADD
Show: