Pages

Thursday, November 27, 2008

Set focus on a particular field on an EP page

With the AX 2009 Enterprise Portal you now have an easy way to set focus on a particular field on a page.

These are the steps you need to go through:
  1. The field must be created as or converted to a TemplateField. The "Dynamics AX Bound Field Designer" helps you to that. Add the field to the "Selected Field" list, make it active and click "Convert to Template field"
  2. Switch to the Source view of the page.
  3. It seems like you have to add the label of the fields yourself. This is done by adding the following section to the XML of the TemplateField: HeaderText="<%$ AxLabel:@SYSxxxxx %>
  4. Finally add code to set the focus:

    TextBox TextBox = (TextBox)this.AxGroup1.FindControl("TextBox1");
    if (TextBox != null)
    {
    TextBox.Focus();
    }

Wednesday, November 5, 2008

EP 2009: Edit a record outside a grid

Here is what you can do if you want to edit a record that is not part of a grid.


The record needs to be shown through an AxForm control and on this control you can set the "AutoGenerateEditButton" to True to get an Edit/Update and Cancel button automatically added to the form.


Next you may need to add event handlers to these buttons if you want the system to do something special in case these are clicked.


This is how the event handler for update could look, if you want to run an additional action on the DataSet:


private
void AxForm_MyForm_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)

{


if (e.Exception == null)

{


// Run the approval code


this.MyDataSet.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("MYMethodOnTheDataSet");



// Redirect to the list of invoices


AxUrlMenuItem listpage = new
AxUrlMenuItem("MyMenuItem");

Response.Redirect(listpage.Url.OriginalString);

}

}


And here is how the code for the Cancel button could look:


private
void AxForm_MyForm_ItemCommand(object sender, DetailsViewCommandEventArgs e)

{


if (e.CommandName == "Cancel")

{


this.RedirectToPreviousPage();

}

}


The RedirectToPreviousPage method is a method you have to add yourself. It could look like this:

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("MyMainPage");

Response.Redirect(listpage.Url.OriginalString);

}

}



And finally you must add you new event handler to the event handlers for the two buttons. This is done in the Page_Init method:


protected
void Page_Init(object sender, EventArgs e)

{


this.AxForm_MyForm.ItemUpdated += new
DetailsViewUpdatedEventHandler(AxForm_MyForm_ItemUpdated);


this.AxForm_MyForm.ItemCommand += new
DetailsViewCommandEventHandler(AxForm_MyForm_ItemCommand);

}