Currently, I am utilizing a currency conversion Web Service and I have implemented a Javascript function to display the result upon clicking a button. However, I would like this Javascript function to execute automatically when the page loads. Here is the code snippet that I attempted:
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Javascript", "function(data);", true);
}
Despite my efforts, the function still does not trigger on page load. Below is the Javascript code that I am using:
<script type="text/javascript">
$(function () {
$('#btnConvert').click(function () {
var amount = $('#txtAmount').val();
var from = $('#ddlfrom').val();
var to = $('#ddlto').val();
$.ajax({ type: "POST",
url: "WebService.asmx/CurrencyConversion",
data: "{amount:" + amount + ",fromCurrency:'" + from + "',toCurrency:'" + to + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var dot = data.d.indexOf(".");
var eg = data.d.substring(0, dot + 2);
var eg1 =data.d.substring(11, 50);
$('#currency_converter_result').html(eg + eg1);
}
});
});
});
</script>