IT tutorials
Applications Server

Microsoft Dynamics Ax 2009 : Programming Enterprise Portal Controls (part 1) - AJAX, Session, Context

2/5/2013 4:00:57 PM
- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
This section covers some of the common programming tasks involved in building and modifying Enterprise Portal controls and explains the technology behind them with code samples.


ASP.NET AJAX allows the developer to create ASP.NET Web pages that can update data on the Web page without completely reloading the page. ASP.NET AJAX provides client-side and server-side components that use the XMLHttpRequest object along with JavaScript and DHTML to enable portions of the page to update asynchronously, again without reloading the entire page. With ASP.NET AJAX, you can develop Enterprise Portal Web pages, just as you would any regular ASP.NET page, and you can declaratively mark the components that need to be rendered asynchronously.

Using the UpdatePanel server control, you can enable sections of the Web page to be partially rerendered without an entire page postback. The Dynamics User Control Web part contains the UpdatePanel internally, and ScriptLibrary is included in the master page, so any control that you use in the Web User Control instantly leverages AJAX without you needing to write any explicit markup or code.

For example, if you add a text box and button, writing code for the button’s click event on the server, without AJAX, when you click the button, the entire page refreshes. But when you load the same control through the Dynamics User Control Web part, it leverages AJAX and updates the text box without refreshing the entire page.

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1"
runat="server" onclick="Button1_Click" Text="Button" />


And in the code-behind, update the text box with the current time after 5 seconds.

protected void Button1_Click(object sender, EventArgs e)
     TextBox1.Text = System.DateTime.Now.ToShortTimeString();

If you want to override the AJAX behavior and force a full postback, you can use the PostBackTrigger control in your Web User Control, as shown here.

<%@ Register assembly="System.Web.Extensions, Version=, Culture=neutral, PublicK
eyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        <asp:PostBackTrigger ControlID="Button1" />



All the Web parts in a Web page share the same session in Dynamics AX. Once the page is served, the session is torn down. To optimize performance, you can control the time frame for tearing down the session through a web.config setting. For example, add the Microsoft.Dynamics sectionGroup to web.config as in the following code.

<sectionGroup name="Microsoft.Dynamics">
<section name="Session" type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral,PublicKeyToken=b77a5c561934e089" />


Add the <Microsoft.Dynamics> element under </system.web> and then add the following text to the file.

     <Session Timeout="15" />

Many of the methods you use in the Enterprise Portal framework to add code to User Controls require access to the Session object. You need to pass the Session object when using proxy classes. You can access the Session object through the Web part hosting the User Control, as shown here.

        AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);
        return webpart == null ? null : webpart.Session;


Context is a data structure used to share data related to the current environment and user actions taking place with different parts of a Web application. Context lets you know what’s happening in one control so you can react to it via another control or Web part, or pass that information to a new page. Generally, information about the current record the user is working on forms the context. For example, when the user selects a row in a grid view, other controls might need to get information about the newly selected row to react.

AxContext is an abstract class that encapsulates the concept of the context. AxTableContext and AxViewContext derive from and implement AxContext. AxTableContext is for table-based context, and AxViewContext is for data set view context. A view can contain more than one table, so it contains an AxTableContext object for each table in the view in the TableContextList collection. The RootTableContext property returns the TableContext of the root table in that data set view. AxViewDataKey uniquely identifies the AxViewContext, and it contains the TableDataKeys collection. AxTableDataKey uniquely identifies AxTableContext. An event is raised whenever the context changes. If the context is changed within the Web User Control, the CurrentContextChanged event is raised. If the context changes from other Web parts that are connected to it, the ExternalContextChanged event is raised.

You can write code in these events on the AxBaseWebPart from your Web User Control and use the CurrentContextProviderView or ExternalContextProviderView and ExternalRecord properties to get the record associated with the context. You can fire all these events programmatically from your application logic by calling FireCurrentContextChanged or FireExternalContextChanged so that all other connected controls could react to the change you made through your code.

Following is sample code to fire the CurrentContextChanged event.

void CurrentContextProviderView_ListChanged(object sender, System.ComponentModel.
ListChangedEventArgs e)
/* The current row (which is the current context) has changed -
 update the consumer webparts.Fire the current context change event to refresh
 (re-execute the query) the consumer webparts
AxBaseWebPart webpart = this.WebPart;


Sample code for getting the record from the connected Web part follows. First subscribe to the ExternalContextChanged event in the consumer Web User Control, as here.

protected void Page_Load(object sender, EventArgs e)
   //Add Event handler for the ExternalContextChange event. Whenever selecting
//the grid of the provider Web part changes, this event gets fired.

        (AxBaseWebPart.GetWebpart(this)).ExternalContextChanged += new


Then get the record passed through the external context, as shown here.

    void AxContextConsumer_ExternalContextChanged(object sender, Microsoft.Dynamics.
Framework.Portal.UI.AxExternalContextChangedEventArgs e)
        //Get the AxTableContext from the ExternalContext passed through web part
connection and construct the record object
        //and get to the value of the fields
        IAxaptaRecordAdapter currentRecord = (AxBaseWebPart.GetWebpart(this)).
   if (currentRecord != null)
   lblCustomer.Text = (string)currentRecord.GetField("Name");
- 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
- Microsoft Dynamic GP 2010 : Dynamics GP System - Additional setup considerations
- Microsoft Dynamic GP 2010 : Dynamics GP System - Users and security, Sales and purchase taxes
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
programming4us programming4us
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