programming4us
 
Applications Server
 

Microsoft Dynamics Ax 2009 : Programming Enterprise Portal Controls (part 3) - Labels, Formatting, Error Handling

2/5/2013 4:04:02 PM

Labels

Dynamics AX uses a localizable text resource file, the label file, to provide messages to the user and for user interface text, Help text in the status bar, captions, and so on. You can use labels to specify the user interface text in Web User Controls and for the AOT Web node element properties. You can add labels by setting the Label property in the AOT or by using X++ code.

When you use data-bound controls such as AxGridView or AxForm for the user interface, the bound fields automatically pick the label associated with the field in the AOT and render it in the user’s language at run time.

If you want to show a label in your Web User Control for non-data-bound scenarios, use the AxLabel expression.

AxLabel is a standard ASP.NET expression that looks up the labels defined in the AOT and renders them in the user’s language when the page is rendered. To add the AxLabel expression, you can use the expression editor available in the design view of the User Control by clicking the button that appears on the (Expressions) property. Alternatively, you can type the expression directly in the markup, like this.


<asp:Button runat="server" ID="ButtonChange" Text="<%$ AxLabel:@SYS70959 %>"
OnClick="ButtonChange_Click" />

					  


You can also add labels through code using the Labels class, as shown here.

string s = Microsoft.Dynamics.Framework.Portal.UI.Labels.GetLabel("@SYS111587");

					  


Enterprise Portal caches the labels for all 41 languages for better performance. So if you add or change a label in the AOT, you need to clear the cache on the Enterprise Portal site by using the Refresh AOD admin option.

Formatting

Dynamics AX is a truly global product, supporting multiple languages and used in many countries. Displaying data in the correct format for each localized version is a critical requirement for any global product. Through metadata, the Enterprise Portal framework recognizes the user’s current locale and system settings and automatically displays data in the correct format in the data-bound controls.

If you’re not using data-bound controls and want your unbound ASP.NET controls to be formatted just like Enterprise Portal controls, you can leverage the AxValueFormatter class in the Enterprise Portal framework. This class implements ICustomFormatter and the IFormatProvider interface and defines a method that supports custom, user-defined formatting of an object’s value and provides a mechanism for retrieving an object to control formatting. For the various data types, specific ValueFormatter classes derived from AxValueFormatter are implemented: AxStringValueFormatter, AxDateValueFormatter, AxDateTimeValueFormatter, AxTimeValueFormatter, AxRealValueFormatter, AxNumberValueFormatter, AxGuidValueFormatter, and AxEnumValueFormatter.

You use AxValueFormatterFactory to create AxValueFormatter objects. You can create any of the preceding formatters, or you can create a formatter based on an EDT in Dynamics AX. The data type for the extended data is retrieved from the metadata object for the EDT, and the culture information comes from the context. The various rules for languages and countries, such as number formats, currency symbols, and sort orders, are aggregated into a number of standard cultures. The Enterprise Portal framework identifies the culture based on the user’s language setting in Dynamics AX and makes this information available in the context. Formatter objects have a Parse method you can use to convert a string value back into the underlying data type. For example, the following code formats the data based on a given EDT.

private string ToEDTFormattedString(object data, string edtDataType)
    {
   ExtendedDataTypeMetadata edtType = MetadataCache.GetExtendedDataTypeMetadata(
            this.AxSession,
            ExtendedDataTypeMetadata.TypeNum(this.AxSession, edtDataType)
        );
        IAxContext context = AxContextHelper.FindIAxContext(this);
        AxValueFormatter valueFormatter = AxValueFormatterFactory.
CreateFormatter(this.AxSession, edtType, context.CultureInfo);
        return valueFormatter.FormatValue(data);
    }Validation

					  


You use ASP.NET validator controls to validate user input on the server as well as (optionally) on the client (browser). The Enterprise Portal framework has ASP.NET validators specific to Dynamics AX: AxBaseValidator derives from BaseValidator, and AxValueFormatValidator derives from AxBaseValidator. Both are metadata driven and are used intrinsically by bound fields, but you can also use them in unbound scenarios.

ASP.NET validators are automatically validated when a postback that causes validation occurs. For example, an ASP.NET Button control causes validation on the client and the server when clicked. All validators registered on the page are validated. If any validator is found to be invalid, the page becomes invalid, and Page.IsValid returns false.

The importance of Page.IsValid is best highlighted with an example. Let’s say you add an ASP.NET button in which some business logic is performed in OnClick before it is redirected. As mentioned, the button causes validation by default, so validators are executed before the OnClick event is fired. If you don’t check whether the page is valid in your OnClick, you will be redirected even though a validation error that requires the user’s attention occurs.

Enterprise Portal controls such as AxForm and AxGridView won’t perform the requested action if validation fails and navigates away from the page. The Dynamics AX validator controls automatically write any validation errors to the Infolog.

Best Practices

When you’re using ASP.NET controls directly rather than using Enterprise Portal controls, as a best practice, make sure the Pages.IsValid flag is checked before any actions, such as navigating away from the current page, are completed. You want to do this because, in case any errors occur, you want to keep the current page with Infolog displaying the errors for the users so that they will notice them and take corrective action.


Error Handling

In Enterprise Portal, .NET Business Connector (including proxies), the metadata, and the data layer all throw exceptions in case of error conditions. The Enterprise Portal ASP.NET controls automatically handle these exceptions, taking appropriate actions and displaying the errors in Infolog.

Exceptions in Enterprise Portal are divided into three categories. These exception categories are defined in the enumeration AxExceptionCategory:

  • NonFatal The exception handling code should respond appropriately and allow the request to continue normally.

  • AxFatal Indicates that an unrecoverable error has occurred in Enterprise Portal. Enterprise Portal content will not display. Content not related to Enterprise Portal should display as expected.

  • SystemFatal Indicates that a serious error, such as out of memory, has occurred and the request must be aborted. Errors of this kind often cause an HTTP error code 500.

If your code directly calls methods in data or metadata layers from Enterprise Portal or with proxy class calling X++ methods, it must handle these exceptions. The following code shows how to use AxControlExceptionHandler in the try-catch statement to handle exceptions.

Try
{
    // Code that may encounter exceptions goes here.
}
catch (System.Exception ex)
{   AxExceptionCategory exceptionCategory;
    // Determine whether the exception can be handled.
    if (AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory)
== false)
    {
        // The exception was fatal and cannot be handled. Rethrow it.
        throw;
    }
    if (exceptionCategory == AxExceptionCategory.NonFatal)
    {
   // Application code to properly respond to the exception goes here.
    }
}

					  


AxControlExceptionHandler tries to handle Dynamics AX exceptions based on the three exception categories just mentioned. It returns true if the exception is NonFatal.

 
Others
 
- Microsoft Dynamics Ax 2009 : Programming Enterprise Portal Controls (part 2) - Data, Metadata
- Microsoft Dynamics Ax 2009 : Programming Enterprise Portal Controls (part 1) - AJAX, Session, Context
- Microsoft Dynamics GP 2010 : Speeding up month-end processing with Reconcile to GL functionality
- Microsoft Dynamics GP 2010 : Getting control of printing with Named Printers
- Microsoft Dynamics GP 2010 : Speeding up entry by Copying a Purchase Order
- BizTalk Server 2009 : Handling Ordered Delivery
- BizTalk Server 2009 : Implementing Dynamic Parallel Orchestrations
- SharePoint 2010 : Service Applications - Managing service application associations
- SharePoint 2010 : Service Applications - Creating a custom service application proxy group
- SharePoint 2010 : Service Applications - Creating custom security for a service
 
 
REVIEW
 
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- Sigma 24mm f/1.4 DG HSM Art

- Canon EF11-24mm f/4L USM

- Creative Sound Blaster Roar 2

- Alienware 17 - Dell's Alienware laptops

- Smartwatch : Wellograph

- Xiaomi Redmi 2
 
VIDEO TUTORIAL
 
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
 
Top 10
 
- How To Install Android Market & Google Apps On Kindle Fire
- How To Make Ubuntu Look Like Windows 7
- How To Add A New Account in MS Outlook 2013
- Get Android & Mac OS X Style Gadgets For Windows 7 & Windows 8 With XWidget
- How To Activate Microsoft Office 2013
- How To Install Actual Facebook App On Kindle Fire
- How To Create, View And Edit Microsoft Office Files On Kindle Fire
- Download Attractive Business PowerPoint Templates For Free At SlideHunter
- How To Use And Enable Hibernate & Sleep Mode In Windows 8
- How To Get Microsoft Office 2013 Trial Product Key From Microsoft