Results 1 to 3 of 3

Thread: ASP.NET Question

  1. #1
    Join Date
    May 2003

    ASP.NET Question

    I'm reading the Sams "Teach Yourself ASP.NET in 24 hours" book, and I like it a lot. But when I tried Chapter 3's "Creating Our First ASP.NET Web Page" financial caluclator (see complete code below), I didn't get any response after testing it out.

    So I then went to the Sams Publishing website at http://www.samspublishing.com/articl...32471&seqNum=3 to directly copy & paste the referenced script into the page. When I refreshed the page, and tried the calculator again, I still did not receive any result on the Label. If anyone can review the code included below, and let me know if and how I'm doing something wrong, it would be greatly appreciated. Thanks!

    <%@ Page Language="VB" Debug="true" %>
    <script runat="server">
    Sub performCalc_Click(sender As Object, e As EventArgs)
    	'Specify constant values
    	Const INTEREST_CALCS_PER_YEAR as Integer = 12
    	Const PAYMENTS_PER_YEAR as Integer = 12
    	'Create variables to hold the values entered by the user
    	Dim P as Double = loanAmount.Text
    	Dim r as Double = rate.Text / 100
    	Dim t as Double = mortgageLength.Text
    	Dim ratePerPeriod as Double
    	ratePerPeriod = r/INTEREST_CALCS_PER_YEAR
    	Dim payPeriods as Integer
    	payPeriods = t * PAYMENTS_PER_YEAR
    	Dim annualRate as Double
    	annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR * Math.Log(1+ratePerPeriod)) - 1
    	Dim intPerPayment as Double
    	intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) - 1) * payPeriods
    	'Now, compute the total cost of the loan
    	Dim intPerMonth as Double = intPerPayment / PAYMENTS_PER_YEAR
    	Dim costPerMonth as Double
    	costPerMonth = P * intPerMonth/(1-Math.Pow(intPerMonth+1,-payPeriods))
    	'Now, display the results in the results Label Web control
    	results.Text = "Your mortgage payment per month is $" & costPerMonth
    End Sub
        <form runat="server">
                Mortgage Amount:
                <asp:TextBox id="loanamount" runat="server"></asp:TextBox>
                Annual Interest Rate:
                <asp:TextBox id="rate" runat="server"></asp:TextBox>
                Mortgage Length:
                <asp:TextBox id="mortgageLength" runat="server"></asp:TextBox>
                <asp:Button id="performCalc" runat="server" Text="Compute Monthly Cost"></asp:Button>
                <asp:Label id="results" runat="server"></asp:Label>
            <!--Insert web controls here -->

  2. #2
    Join Date
    Nov 2004
    New Jersey
    All you need is an onclick="sub name" event in your button control. The way the code is now, when you click the button it doesn't go to your subroutine. That is why you don't see anything on the label.

    Here is the addition:
    <asp:Button id="performCalc" runat="server" Text="Compute Monthly Cost" onclick="performCalc_Click"></asp:Button>

    It should work now.


  3. #3
    Join Date
    May 2003
    Boy do I feel dumb. I knew that it had to be something simple. Thanks for the quick response...I really appreciate your help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles