ASP.NET

To embed a Corda® image into an ASP.NET Web application, use the .NET version of Corda Embedder. The .NET Corda Embedder is written in C#, but can be used with both C# and Visual Basic. This section provides code examples for both.

Embedding a Corda image into an ASP.NET application can be broken down into the following steps:

The example code at the end of this section shows how to embed a Corda image in ASP.NET using either C# or Visual Basic.

Note: This documentation assumes that you are familiar with .NET.

Referencing the Library

Before using Corda Embedder in a Web application, first add a reference to the Corda Embedder .NET library.

To add a reference to CordaNetEmbedder.dll

  1. Open the Web application into which you want to embed the Corda image.

    Add a reference to the Corda Embedder library for every Web application that uses the Corda Embedder.

  2. Select Project > Add Reference.

  3. Be sure that the .NET tab is selected, and then click the Browse button.

  4. Locate the CordaNetEmbedder.dll file, select it, and then click OK .

    By default, this file is in <product_root>\Server\dev_tools/embedder/dotnet.

    The CordaNetEmbedder should now be listed in the Selected Components box.

  5. Click OK to finish adding the reference.

Importing the Namespace

After referencing the Corda Embedder library, import the Corda namespace into any C# (.cs) or Visual Basic (.vb) files in the Web application that contains Corda Embedder code.

C#

To import the Corda namespace in C#, use the using directive. Typically, at the top of a C# file, there are already a list of using directives. Simply add the following directive at the bottom of the list:

using Corda;

Visual Basic

To import the Corda namespace in Visual Basic, place an import statement at the top of the file (before the Class declaration). For example:

Imports Corda

Placing a Control in a Web Form

As you probably already know, ASP.NET pages consists of two separate files: the layout file (the .aspx file), and the class file (the .vb or .cs file). The layout (.aspx) file specifies information about the layout of controls and components within the page, as well as static HTML. The class (.cs or .vb) file contains any code that is used within the page.

When embedding a Corda image into an ASP.NET page, modify both of these files. In the layout (.aspx) file, place a control to contain the Corda image. The class (.cs or .vb) file contains all of the Corda Embedder code.

This example uses a generic HTML control to embed a Corda image—the <div> tag. Insert this tag directly into the HTML source code for the Web form.

Note: There are many other ways of embedding a Corda image in a Web page that do not use controls, including simply outputting getEmbeddingHTML through Response.Write. To keep things simple, this section focuses only on embedding the Corda image within an HTML control.

To place a control for the Corda image in the Web form

  1. Open the layout (.aspx file for the ASP.NET page where you want to add the Corda image.

  2. Select View > HTML Source.

  3. Locate the place within the Web page where you want to place the Corda image.

  4. Add the following code:

    <div id="Corda1" runsat="server"></div>

    Set the id attribute to any unique value. The runat="server" attribute is required.

The example below shows a sample .aspx file.

Example .aspx File

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="MyImage.WebForm1" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

<HEAD>

<title>WebForm1</title>

<meta content="Microsoft* Visual Studio 7.0" name="GENERATOR">

<meta content="C#" name="CODE_LANGUAGE">

<meta content="Javascript*" name="vs_defaultClientScript">

<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">

</HEAD>

<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">

</form>

<div id="Corda1" runat="server"></div>

</body>

</HTML>

Note: This example page is for C#. The Visual Basic version of this page is very similar, and the process of adding a control to either version of the .aspx file is the same.

Inserting Corda Embedder Code

Typically, put the Corda Embedder code in the Page_Load method of the ASP.NET's class file. This file has the exact same name as the layout file, with the addition of a .cs or .vb extension. The Page_Load method contains any code that should run immediately before serving the page to a Web browser.

To specify the Corda Embedder code, open ASP.NET's class file, locate the Page_Load method, and insert the necessary code below the line that reads:

//Put user code to initialize the page here

Syntax Notes for Visual Basic

No Semi-colons at the End of Lines

Note: This applies to Visual Basic .NET.

Visual Basic syntax requires that you do not have a semi-colon at the end of a line of code. Since other languages either require a semi-colon, or are indifferent, most of the example code in this documentation uses a semi-colon at the end of each line of code. Remove any semi-colons from example code when using it with ASP.

Instantiating a Corda Embedder Object

Instantiate an instance of the Corda Embedder object in either C# or Visual Basic.

C#

To instantiate a Corda Embedder object in C#, use code similar to the following:

CordaEmbedder myImage = new CordaEmbedder();

Visual Basic

To instantiate a Corda Embedder object in Visual Basic, use code similar to the following:

Dim myImage = New CordaEmbedder()

Setting the Server Information

Corda Embedder needs to know two Corda Server™ addresses: the address that the Web client uses to access Corda Server (externalServerAddress), and the address that Corda Embedder uses to access Corda Server (internalCommPortAddress). For more information about determining these addresses, see Identifying Server Addresses.

C#

If Corda Embedder communicates with Corda Server at 10.0.1.1:2002, and the Web clients request images from http://<server_address>:2001, include the following C# code to generate the Corda image:

myImage.externalServerAddress = "http://<server_address>:2001";

myImage.internalCommPortAddress = "10.0.1.1:2002";

Visual Basic

If Corda Embedder communicates with Corda Server at 10.0.1.1:2002, and the Web clients request images from http://<server_address>:2001, include the following Visual Basic code to generate the Corda image:

myImage.externalServerAddress = "http://<server_address>:2001"

myImage.internalCommPortAddress = "10.0.1.1:2002"

Specifying Image Information

After specifying server address information, give Corda Embedder some information about the Corda image you want to embed.

There are numerous Corda Embedder commands to specify image information, which are consistent in all Web application environments (with the exception of several syntax differences, as previously explained in Syntax Notes for Visual Basic). Thus, it is unnecessary to discuss each of these commands individually at this time.

The table below provides links to more information about Corda image features and components:

Topic

Where To Go

Annotations

Data Annotations in the Corda Builder™ User Guide

Content Delivery / Presentation Control

Image Deployment Issues and Descriptive Text Settings

Data

Connecting to Data Files and Connecting to Databases

Drilldown

Building Drilldown

Graph or Map Customization

Dynamically Customizing Graphs and Maps

Image Size & Format

Changing the Image Format and Changing Image Size

Writing the Image to a Web Page

When you are ready to write the embedding HTML to a Web page, place the following code segment at the location in the Active Server Page where you want the Corda image to appear.

When you are ready to write the embedding HTML to the control, output the getEmbeddingHTML method to the control.

To write the embedding HTML to an HTML control

  1. Declare an HtmlGenericControl object.

    Which the object name can be anything, Corda recommends giving it the same name as the control you previously created (in the Placing a Control in a Web Form steps above). In this example, the object is named Corda1.

    In C#, use the following command:

    HtmlGenericControl Corda1;

    In Visual Basic, use the following command:

    Dim Corda1 As HtmlGenericControl

  2. Using the FindControl method, assign this object to the HTML control you previously created for the Corda image (in the Placing a Control in a Web Form steps above).

    The FindControl method searches the layout page for a Web server or HTML control that has the specified id (in this case Image1), and returns the corresponding object, which you can then access from the code.

    In C#, cast the returned object of the FindControl method as HtmlGenericControl. Thus, the assignment statement looks like this:

    Corda1 = (HtmlGenericControl)FindControl("Corda1");

    In Visual Basic, the assignment statement looks like this:

    Corda1 = FindControl("Corda1")

    Note: Combine these first two steps, if desired.

  3. Assign the InnerHTML attribute of this object to the string returned by Corda Embedder's getEmbeddingHTML method.

    In C#, make this assignment code similar to the following:

    Corda1.InnerHtml = myImage.getEmbeddingHTML();

    In Visual Basic, make this assignment with code similar to the following:

    Corda1.InnerHTML = myImage.getEmbeddingHTML

Complete Example Code

The code sample below demonstrates embedding a Corda image with ASP.NET (C#). The accompanying layout (.aspx) file is that from the example .aspx file above.

Note: To produce an example map instead of a graph, replace examples/bar.itxml with examples/map/australia_combo.itxml in the code designating the Image Template file.

Note: Code generated by the Web form designer has been omitted from the example below.

Embedding a Corda Image in an ASP.NET (C#)

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using Corda;

 

namespace myImage

{

public class WebForm1: System.Web.UI.Page

{

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

 

CordaEmbedder myImage = new CordaEmbedder();

HtmlGenericControl Corda1 = (HtmlGenericControl)FindControl("Corda1");

myImage.externalServerAddress = "<server_address>:2001";

myImage.internalCommPortAddress = "localhost:2002";

myImage.imageTemplate = "image_templates\examples\bar.itxml";

myImage.width = 600;

myImage.height = 400;

myImage.pcScript = "title.setText(Hello World)";

Corda1.InnerHtml = myImage.getEmbeddingHTML();

}

 

#region Web Form Designer generated code has been omitted

#endregion

}

}

 

The code sample below demonstrates embedding a Corda image with ASP.NET (Visual Basic).

Embedding a Corda Image in an ASP.NET (Visual Basic)

Imports Corda

 

Public Class WebForm1

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code (has been omitted)"

#End Region

 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

 

Dim myImage = New CordaEmbedder()

Dim Corda1 As HtmlGenericControl = FindControl("Corda1")

myImage.externalServerAddress = "<server_address>:2001"

myImage.internalCommPortAddress = "localhost:2002"

myImage.imageTemplate = "image_templates\examples\bar.itxml"

myImage.height = 400

myImage.width = 600

myImage.pcScript = "title.setText(Hello World)"

Corda1.InnerHTML = myImage.getEmbeddingHTML

End Sub

End Class