IT tutorials
 
Applications Server
 

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

2/5/2013 4:00:57 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
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.

AJAX

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)
    {
     System.Threading.Thread.Sleep(5000);
     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=3.5.0.0, Culture=neutral, PublicK
eyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="Button1" />
    </Triggers>
</asp:UpdatePanel>

					  


Session

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" />
</sectionGroup>

					  


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

<Microsoft.Dynamics>
     <Session Timeout="15" />
</Microsoft.Dynamics>


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

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;
webpart.FireCurrentContextChanged();
   }

					  


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
EventHandler<Microsoft.Dynamics.Framework.Portal.UI.AxExternalContextChangedEventArgs>
(AxContextConsumer_ExternalContextChanged);
}

					  


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)).
ExternalRecord;
        {
   if (currentRecord != null)
            {
   lblCustomer.Text = (string)currentRecord.GetField("Name");
            }
        }
    }
					  
 
Others
 
- 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
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us