using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None; if (!IsPostBack) //page loading for the first time { for (int i = 50; i <= 500; i+=50) { ddlBorrowAmount.Items.Add(i.ToString()); } } } //end of Page_Load() protected void btnCalculate_Click(object sender, EventArgs e) { if (IsValid) //if pass validation { int borrowAmount = Convert.ToInt32(ddlBorrowAmount.SelectedValue); decimal yearlyInterestRate = Convert.ToDecimal(txtInterestRate.Text); int years = Convert.ToInt32(txtYears.Text); decimal futureDebt = this.CalculateFutureDebt(borrowAmount, yearlyInterestRate, years); lblFutureDebt.Text = futureDebt.ToString("c"); } //end of if } //end of btnCalculate_Click() protected decimal CalculateFutureDebt(int borrowAmount, decimal yearlyInterestRate, int years) { decimal futureDebt = borrowAmount; for (int i = 0; i < years; i++) { futureDebt = futureDebt * (1 + (yearlyInterestRate / 100)); } return futureDebt; } //end of CalculateFutureDebt() protected void btnClear_Click(object sender, EventArgs e) { ddlBorrowAmount.SelectedIndex = -1; txtInterestRate.Text = ""; txtYears.Text = ""; lblFutureDebt.Text = ""; } //end of btnClear_Click() }