Currency Label control for ASP.NET Web Forms

The purpose of this control is to show the converted amount (of specified source currency) in target currency. It may convert currency for current day or any day before that.

Here is the sample code:

<body>
    <form id="form1" runat="server">
    <div> Here is what $7.25 looks like:<br />
        <asp:CurrencyLabel runat="server" CurrencyFrom="USD" CurrencyTo="EUR" MoneyValue="7.25" Font-Bold="true" Text="EUR {0}" /><br />
        <asp:CurrencyLabel runat="server" CurrencyFrom="USD" CurrencyTo="GBP" MoneyValue="7.25" Font-Bold="true" Text="GBP {0}" /><br />
        <asp:CurrencyLabel runat="server" CurrencyFrom="USD" CurrencyTo="AUD" MoneyValue="7.25" Font-Bold="true" Text="AUD {0}" /><br />
        DKK&nbsp;<asp:CurrencyLabel runat="server" CurrencyFrom="USD" CurrencyTo="DKK" MoneyValue="7.25" Font-Bold="true" /><br />
    </div>
    </form>
</body>

 

And here is the result:

 

This control inherits from standard label control, and so it has all the standard properties of the original label. However, it has additional properties, described here.

PROPERTIES OF WEB CONTROL

Text (string)

The standard Text property is replaced with conversion result, unless the specified expression contains the “{0}” mark. In that case, the Text value will be formatted, with {0} being replaced with the result of the conversion result.

CurrencyFrom (string)

The 3-letter code of the source currency. For example, USD for U.S. Dollar and EUR for Euro. You can see all available codes in Wikipedia: http://en.wikipedia.org/wiki/ISO_4217

CurrencyTo (string)

The 3-letter code of the target currency.

MoneyValue (double)

The amount of source currency to be converted.

Precision (byte)

Number of digits after decimal separator to keep after formatting. Default value is 2, producing numbers like “1.25” or “3.70”. Increasing the precision will add digits, but result may still be rounded by conversion service.

ErrorMessage (string, read-only)

In case of error, this property contains the error message.

UseSSL (boolean)

Whether to use SSL when connecting to web service. By default is false. Please bear in mind, that there might be significant performance impact in using SSL.

ConversionDate (DateTime, nullable)

The date of conversion. By default it’s not set, which produces the most current conversion.

CachePeriod (Int16)

Time period, in minutes, to store conversion result in server memory. ASP.NET Caching engine is used for that. Default value is 180, which is equivalent to 3 hours. Whenever other control will need to convert the same amount using the same currencies, the result will be supplied from memory.

Bear in mind, that in a web farm you might need to configure centralized caching in web.config file, so different farm nodes would share results.

Caching is beneficial for both the performance and API key usage (if the key usage is limited).

SETTING UP THE WEB.CONFIG FILE

In order for Currency Label to be able to convert your values, it needs to know the Mondor API Key. You can get your API Key by following the demo key (http://mondor.org/CurrencyExchangeServiceDemo.aspx) or purchasing the one that suits you. The API key is 32-chars long string, which should be kept in your web.config file.

Example:

</system.web>

<appSettings>
<add key="MondorAPIKey" value="278362449bc04523ae2eb0a302d942ff"/>
</appSettings>

</configuration>

When you change the value in your web.config file, your ASP.NET application restarts, which means all settings are effective immediately.

 
GETTING READY

In order to start using the Currency Label control, do the following:

1. Download the DLL file and reference it in your project.

2. Acquire the API key and add it to your web.config file.

3. Add markup to your page, like shown at the beginning of the page.

Since this control works exactly like the normal label, you should be familiar with it already. Now, run your sample and ensure it can convert your amounts.

The last warning: the demo key will only allow about 200 conversions per day. After you reach your daily cap, the result you get is 0, until the midnight (and I think its midnight in Western Europe, like GMT +1).

SYSTEM REQUIREMENTS

.NET Framework 4.5

LICENSE

This control is freeware. There is no license attached at the moment.

DOWNLOAD:

Current version 1.0 (beta)

CurrencyLabel.rar (498.53 kb)

blog comments powered by Disqus

Month List