AxPopup Controls

AxPopup controls are used to open a page in a popup browser window and upon closing a popup page, pass data from the popup page back to the parent page and trigger an OnPopupClosed server event on the parent. This functionality is encapsulated in two controls - AxPopupParentControl to be used in the parent page and AxPopupChildControl to be used on the popup page. They both derive from AxPopupBaseControl. These controls are AJAX-compatible, so they can be created conditionally as part of a partial update.

Data can be passed from the popup page back to the parent page using AxPopupField objects. They are exposed via the Fields property of the AxPopupBaseControl, from which both AxPopupParentControl and AxPopupChildControl are derived.

AxPopupParentControl and AxPopupChildControl have fields with the same names. When the popup page closes, the value of each field of the AxPopupChildControl is assigned (via client-side script) to the correspondent field in the AxPopupParentControl.

AxPopupField can optionally be associated with another control, such as TextBox or any other control, by assigning its TargetId property to the ID property of the target control. This is useful, for instance, when the popup page has a TextBox control. In order to pass the user input to the parent page upon closing the popup, and to do it entirely on the client hence avoiding the round trip, a field needs to be associated with the TextBox control.

In AX 2009 this approach is used in number of places and one such control is the Business Relations list.

The AxPopupField control is placed in the user control displaying the list. In the code behind, the toolbar action calls the popup using the GetOpenPopUpEventReference method. Both the parent control and the childcontrol uses the field with the same name hiddenCustomerAccountNo to pass the values back& forth. The childcontrol gets the value from the text box using the TargetControlID.

smmBusRelListGrid.ascx

List containing the ParentControl from the popup

<dynamics:AxPopupParentControl ID="PopupConvertCustomer" runat="server" PopupHeight ="180" PopupWidth="400"  >

    <dynamics:AxPopupField name="hiddenCustomerAccountNo"  />   

</dynamics:AxPopupParentControl>

smmBusRelListGrid.ascx.cs

Code behind opening up the popup using GetOpenPopUpEventReference

protected void AddCustomerAccountNoScript(SetMenuItemPropertiesEventArgs e, string custAccount)

    {

        AxUrlMenuItem menuItem = new AxUrlMenuItem(CUSTOMER_ACCOUNT_DIALOG);

        DataSetViewRow row = this.GetCurrentDataSetViewRow();

        if (row != null)

        {

            AxTableContext context = AxTableContext.Create

            (row.GetTableDataKey(row.DataSetView.Metadata.RootDataSource, null));

 

            menuItem.MenuItemContext = context;

 

            //Adding the CustAccount QueryString variable

            if (custAccount != string.Empty)

            {

                menuItem.ExtraParams.Add("CustAccount", custAccount);

            }

            menuItem.RemoveNavigation = true;

 

            //Calling the javascript function to set the properties of opening the customer account

            //on clicking the menu items.

            e.MenuItem.ClientOnClickScript = this.PopupConvertCustomer.GetOpenPopupEventReference(menuItem);

        }

    }

CustomerAccountDialog.ascx

The popup form  transferring  the value entered in the target  to the parent control by using the same control name.

<div>

    <br />

    <br />

    <table style="width: 100%">       

        <tr>

            <td class="PopoverFormText">

                <asp:Label ID="lblCustAccount" runat="server" Text="<%$ axlabel:@SYS7149 %>"></asp:Label>                       

            </td>

            <td class="PopoverFormText" >

                <asp:TextBox ID="txtCustAccount" runat="server" MaxLength="20" ></asp:TextBox>  

                <dynamics:AxPopupChildControl ID="popupChild" runat="server">

                    <dynamics:AxPopupField name="hiddenCustomerAccountNo" TargetControlId="txtCustAccount" />

                </dynamics:AxPopupChildControl>       

            </td>                   

        </tr>

        <tr><td colspan="3"><br /> <hr class="hr" />

            </td></tr>

        <tr>

            <td align="right" colspan="2">

            <asp:Button  id = "OkButton" CssClass="okCancelButton" runat ="server"  Text="<%$ axlabel:@SYS5473 %>" onclick="OkButton_Click" />

            <input id="CancelButton" class="okCancelButton" runat ="server" type="button" value="<%$ axlabel:@SYS50163 %>" onclick="window.close();" />

           

            </td>

            <td style="width: 10%"></td>

        </tr>

    </table>   

</div>

 

CustomerAccountDialog.ascx.cs

Pop up closed after validing the data entered in the popup , giving control back to the parent page.

//Used to validate the CustAccount no etered.

    protected void OkButton_Click(object sender, EventArgs e)

    {

        try

        {

            if (this.txtCustAccount.Text.Equals(string.Empty))

            {

                //Displaying error message: Account number is not specified

                DisplayInfolog(InfoType.Error, "@SYS24085");

                return;

            }

 

            //Validating the Customer Account no. entered

            if (!ApplicationProxy.SmmOpportunityStatusUpdate.checkCustomerAccount(this.AxSession.AxaptaAdapter, this.txtCustAccount.Text))

            {

                return;

            }

 

            //Calling the script for closing the dialogbox

            this.popupChild.ClosePopup(true, true);

        }

        catch (Exception ex)

        {

            AxExceptionCategory exceptionCategory;

            // This returns true if the exception can be handled here

            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))

            {

                // The exception was fatal - in this case we re-throw.

                throw;

            }

        }

    }