title: Loan Calculator in ASP.NET from a Console Application
body: <p>I just finished working on a console application in witch I created a loan calculator.  My code is as follows:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace LoanCalculator
  {
      public class LoanCalculator
      {
  
          public static void Main(string[] args)
          {
              // declare variables
              double principle = 0; 
              double years = 0;
              double interest = 0;
              string principleInput, yearsInput, interestInput;
  
  
              // User input for Principle amount in dollars
              Console.Write("Enter the loan amount, in dollars(0000.00): ");
              principleInput = Console.ReadLine();
              principle = double.Parse(principleInput);
              //Prompt the user to reenter any illegal input
              if (principle &lt; 0)
              {
                  Console.WriteLine("The value for the mortgage cannot be a negative value");
                  principle = 0;
              }
  
  
              // User input for number of years
              Console.Write("Enter the number of years: ");
              yearsInput = Console.ReadLine();
              years = double.Parse(yearsInput);
              //Prompt the user to reenter any illegal input
              if (years &lt; 0)
              {
                  Console.WriteLine("Years cannot be a negative value");
                  years = 0;
              }
  
              // User input for interest rate
              Console.Write("Enter the interest rate(%): ");
              interestInput = Console.ReadLine();
              interest = double.Parse(interestInput);
              //Prompt the user to reenter any illegal input
              if (interest &lt; 0)
              {
                  Console.WriteLine("The value for the interest rate cannot be a negative value");
                  interest = 0;
              }
  
              //Calculate the monthly payment
              //ADD IN THE .Net function call Math.pow(x, y) to compute xy (x raised to the y power). 
              double loanM = (interest / 1200.0);
              double numberMonths = years * 12;
              double negNumberMonths = 0 - numberMonths;
              double monthlyPayment = principle * loanM / (1 - System.Math.Pow((1 + loanM), negNumberMonths));
  
              //double totalPayment = monthlyPayment;
  
  
              //Output the result of the monthly payment
              Console.WriteLine(String.Format("The amount of the monthly payment is: {0}{1:0.00}", "$", monthlyPayment));
              Console.WriteLine();
              Console.WriteLine("Press the Enter key to end. . .");
              Console.Read();
  
          }
      }
  }
  </code></pre>
  
  <p>Everything above works out as planned.  I am now trying to convert this into an ASP.NET web application using Visual Studio and I am stuck. My current UI I have set up with 3 labels for principle input (with a text box), loan duration (with radio button list) , and interest rate (with dropdownList).  </p>
  
  <p>My problem I am having is I am trying to get a radiobutton list in for my loan duration (15, 30, or other) as my selections. If the user selects Other, I am trying to implement a textbox for them to type in a value in years.  After the user selects his intended duration I want my InterestRate to be a drop down list item with 1%-10% as options.</p>
  
  <p>I also have a button called "Calculate" where it calculates the solution from the users input. If someone could lead me into the right direction on how to approach this. I am brand new to working with ASP.NET and I am confused how to successfully transform my console application to an ASP.NET project.  Thanks for the help!</p>
  
  <p>My Page looks as follows:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;
  
   &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
       &lt;title&gt;Monthly Mortgage Calculator&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
      &lt;h1&gt;Monthly Payment Loan Calculator&lt;/h1&gt;
      &lt;/div&gt;
  
       &lt;asp:Label ID="Label1" runat="server" Text="Please enter the principle amount"&gt;     &lt;/asp:Label&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
      &lt;asp:TextBox ID="txtPrinciple" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Label ID="Label2" runat="server" 
          Text="Please enter the loan duration in years"&gt;&lt;/asp:Label&gt;
      &lt;br /&gt;
      &lt;asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"&gt;
          &lt;asp:ListItem&gt;15 Years&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;30 Years&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;Other&lt;/asp:ListItem&gt;
      &lt;/asp:RadioButtonList&gt;
      &lt;br /&gt;
    nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;n    bsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
      &lt;asp:TextBox ID="txtYears" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Label ID="Label3" runat="server" Text="Please select the interest rate"&gt;    &lt;/asp:Label&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;
      &lt;asp:DropDownList ID="DropDownList1" runat="server"&gt;
          &lt;asp:ListItem&gt;1&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;2&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;3&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;4&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;5&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;6&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;7&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;8&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;9&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;10&lt;/asp:ListItem&gt;
      &lt;/asp:DropDownList&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Button ID="Button1" runat="server" Text="Monthly Payment" /&gt;
  
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>