IT tutorials
 
Applications Server
 

Microsoft Dynamics Ax 2009 : Programming Enterprise Portal Controls (part 4) - ViewState, Page Life Cycle, Proxy Classes

2/5/2013 4:04:51 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

ViewState

The Web is stateless, which means that each request for a page is treated as a new request, and no information is shared. When loaded, each ASP.NET page goes through a regular page life cycle, from initialization and page load onward. When a user interacts with the page, causing the need for the server to process some control events, ASP.NET posts the values of the form to the same page for processing the event on the server. A new instance of the Web page class is created each time the page is requested from the server. When postback happens, ASP.NET uses the ViewState feature to preserve the state of the page and controls so that any changes made to the page during the round-trip are not lost. The Enterprise Portal framework leverages this feature, and Enterprise Portal ASP.NET controls automatically save their state to ViewState. The ASP.NET page reads the view state and reinstates the page and control state in its regular page life cycle. So you don’t need to write any code to manage the state if you’re using Enterprise Portal controls. But if you want to persist any values in memory variables, you can write code to add or remove items from StateBag in ASP.NET. If you need to save the state of an X++ data set, you can use the pack and unpack design pattern to store the state, as shown here.

public int Counter
{
    get
     {
        Object counterObject = ViewState["Counter"];
        if (counterObject == null)
        {
            return 0;
        }
       return (int)counterObject;
     }
    set
     {
        ViewState["Counter"] = value;
    }
}


The Enterprise Portal framework uses the EPStateStore table in Dynamics AX to store the state of AxDataSourceControl. The states of all other controls are stored in the ASP.NET view state for added security. This storage is per user, and each user can read only his or her information. Writes and deletes are protected with AOS methods, and read is protected via code access permission.

Page Life Cycle

When an Enterprise Portal page runs, it goes through a life cycle in which it performs a series of steps and raises events at various states so developers can write code to control the behavior of the page and its controls, create dynamic controls, and write user interface logic. Understanding the sequence of the page processing and events helps you write the user interface logic at the appropriate level.

Proxy Classes

If you need to call X++ classes or table methods or enums in your Web User Control, the Enterprise Portal framework provides an easy way of creating managed wrappers for these X++ objects and using them in your Web User Control. A proxy file internally wraps the .NET Business Connector calls and provides a simple, easy-to-use, typed interface for C# applications. The proxies file under Web\Web Files\Static Files in the AOT contains information about all the X++ objects for which a proxy file needs to be generated. The proxy generation tool uses this file when the Enterprise Portal site is deployed. The proxy files are automatically created and deployed to the App_Code folder of the IIS Web site. Table 1 describes the various command line options for the proxy generator.

Table 1. Proxy Generator Command Line Options
OptionPurpose
/ classSpecifies the name of a class to generate. The /method option is used to further specify the composition of the generated class type.
/enumSpecifies the name of a base enumeration to generate.
/generateSpecifies the generate mode: optional values are classes, enums, and tables. If the /generate option isn’t specified or if no option value is specified, the /class, /enum, and /table options determine what types are generated.

If the classes value is specified, all AOT classes are generated.

If the enums value is specified, all AOT base enumerations are generated.

If the tables value is specified, all AOT tables are generated.
/methodSpecifies the name of a method to generate. The class (or table) and method name must be specified as follows: class.method.
/methods+Specifies that all methods will be generated, ignoring the methods specified by the /method options.
/methods-Default. Specifies that only the methods specified by the /method options will be generated.
/namespaceSpecifies the namespace for the generated proxies.
/references+Specifies that all class references will be generated. A reference is a generated type that appears as a base class, or as a method return type or parameter type.
/references-Default. Specifies that no class references will be generated.
/tableSpecifies the name of a table to generate. The /method option is used to further specify the composition of the generated class type.
/warnSpecifies the proxy generator warning level: 0 Off, 1 Error, 2 Warn, 3 Info, and 4 Verbose.

For example, to generate a proxy file for the SampleProxy class, add the following code to the Web\Web Files\Static Files\Proxies node in the AOT.

warn:2 /references+ /methods- /namespace:Microsoft.Dynamics.Portal.Application.Proxy

/class:SampleProxy
  /method:SampleProxy.sampleProxiesNoParameters
  /method:SampleProxy.sampleProxiesStaticMethod

					  


The first line of the preceding code provides the generation options for the proxy file. The second line provides information about the X++ class for which the proxy file needs to be generated. When Enterprise Portal is deployed, a SampleProxy.cs is created; it contains two methods and is deployed to the App_Code folder of the IIS Web site.

From Visual Studio, you can right-click the App_Code folder in a Dynamics AX Web project and choose the Generate Proxies option. The Visual Studio add-in generates the proxy files defined in the Proxies file and adds them to the Visual Studio project.

To use the proxy from C# code in the Web User Controls, first add a using statement to the proxy namespace, like this.

using Microsoft.Dynamics.Portal.Application.Proxy;


Then you can access these X++ methods as if they were in C#. You can access some items in the proxy, such as enums, directly, without any additional code. Accessing methods from the proxy requires passing the IAxaptaAdapter object together with the method call. So you need to get the session and pass it to the constructor to create the C# proxy object, as shown here.

protected string NoParamProxyCall_Click(object sender, EventArgs e)
    {
        AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);
        SampleProxy sampleProxy = null;
        sampleProxy = new SampleProxy(webpart.Session.AxaptaAdapter);
        string s = sampleProxy.sampleProxiesNoParameters();
        return s;
    }
 
Others
 
- Microsoft Dynamics Ax 2009 : Programming Enterprise Portal Controls (part 3) - Labels, Formatting, Error Handling
- 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
 
Youtube channel
 
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