Page Redirection

Dynamics AX 2009

When a user has finished performing the task for a page, you may want to display a different page in Enterprise Portal. Do this by redirecting to the new page to display.

Page redirection is used in several locations in the code for a User Control. For instance, the user is returned to the previously displayed page when they click OK or Cancel in a task page. Implementing a single redirection method consolidates the code into one location.

The AxWebSession object keeps track of the URL of the page that was previously displayed for the user. Typically, this is the page the user will be redirected to after they complete a task in the current page. If the previous URL is not available, the user should be redirected to a known page in Enterprise Portal after they complete a task.

The following example is the RedirectToPreviousPage method added for a User Control. This User Control contains an AxForm component and appears on a task page. When the user finishes the task in the page, they are redirected to the previous page. Typically this is a list page from where the action was originally chosen. If the previous page is not available, the user is redirected to a known list page in the role center. Notice how a URL Web menu item is used to specify the page to display.

private void RedirectToPreviousPage()
{
    // Return to the previous page displayed.
    if (!String.IsNullOrEmpty(AxWebSession.GetPreviousURL(this.Page)))
    {
        Response.Redirect(AxWebSession.GetPreviousURL(this.Page));
    }
    else
    {
        // The previous page is not available, so return to a known page.
        // Use the URL Web Menu item from the AOT to specify which
        // page will be displayed.
        AxUrlMenuItem listpage = new AxUrlMenuItem("VehiclesList");
        Response.Redirect(listpage.Url.OriginalString);
    }
}

The redirection method is called from several locations in the User Control code. For example, it is called in the event handler that is run every time that a button on the AxForm for the User Control is clicked. The following code verifies that the Cancel button for the form was clicked. If it was, the redirection method is called to redirect the user to the previous page.

void VehicleForm_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
    if (e.CommandName == "Cancel")
    {
        // Cancel any editing action that had been started.
        this.DataSourceView.CancelEdit();

        // Redirect the user to the previous page.
        this.RedirectToPreviousPage();
    }
}

The redirection method is also called in the event handlers that are run in response to events such as ItemInserted or ItemUpdated. The following example shows the ItemInserted event handler for the AxForm component named VehicleForm. This event handler determines whether the event was successful. If it was, the redirection method is called to redirect the user to the previous page.

void VehicleForm_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
    // Verify whether the operation was successful.
    if (e.AffectedRows == 1)
    {
        this.RedirectToPreviousPage();
    }
}

Community Additions

ADD
Show: