<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="AjaxCurrencyConverter._Default" %>

<%@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="radA" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <radA:RadAjaxServiceManager ID="RadAjaxServiceManager" runat="server">
                <WebServices>
                    <radA:WebServiceReference Path="~/ExchangeRate.asmx" />
                </WebServices>
            </radA:RadAjaxServiceManager>
            &nbsp;
            <table border="0" cellpadding="2">
                <tr>
                    <td width="200px">
                        From Country</td>
                    <td width="200px">
                        To Country</td>
                    <td width="200px">
                        <asp:Button ID="pbCalc" runat="server" Text="Get Xchg Rate" OnClientClick="CallService(); return false;" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:DropDownList ID="ddlFrom" runat="server" Width="150px">
                            <asp:ListItem Text="Canada"></asp:ListItem>
                            <asp:ListItem Text="Finland"></asp:ListItem>
                            <asp:ListItem Text="Germany"></asp:ListItem>
                            <asp:ListItem Text="Sweden"></asp:ListItem>
                            <asp:ListItem Text="Switzerland"></asp:ListItem>
                            <asp:ListItem Text="United States"></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlTo" runat="server" Width="150px">
                            <asp:ListItem Text="Canada"></asp:ListItem>
                            <asp:ListItem Text="Finland"></asp:ListItem>
                            <asp:ListItem Text="Germany"></asp:ListItem>
                            <asp:ListItem Text="Sweden"></asp:ListItem>
                            <asp:ListItem Text="Switzerland"></asp:ListItem>
                            <asp:ListItem Text="United States"></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td>
                        <asp:Label ID="lblRate" runat="server" Text=""></asp:Label>
                    </td>
                </tr>
            </table>
            <asp:Label ID="lblError" runat="Server"></asp:Label>

            <script type="text/javascript">

    function CallService()
    {
        var from=document.getElementById("ddlFrom");
        var to=document.getElementById("ddlTo");

        if(from.value != "" && to.value !="" )
        {
            ExchangeRate.GetExchangRate(from.value, to.value, ServiceCompleteCallback, ServiceErrorCallback);
        }
        else
        {
            alert("Please select two countries!");
        }
    }

    function ServiceCompleteCallback(ResponseAsJSON, ResponseAsXml, ResponseAsText)
    {
        var rate= ResponseAsText;
        var element = document.getElementById("lblRate");
        if(element != null)
        {
            element.innerHTML = rate;
        }        
    }

    function ServiceErrorCallback(args)
    {
        var label = document.getElementById("lblError");
        label.innerHTML = "Error occurred: " + args.ErrorText + "<br />" + "Details: " + args.Text;
    }

            </script>

        </div>
    </form>
</body>
</html>
