.NET Practical Slip 5 Q B

This ASP.Net web application demonstrates form handling, input validation, and simple interest calculation, helping students learn how to create interactive web forms with proper error checking.

Slip 5 Q.B) Problem Statement

Q. Design a web application form in ASP.Net with fields for loan amount, interest rate, and duration. Calculate the simple interest and perform necessary validations, ensuring data has been entered for each field and checking for non-numeric values. Use suitable web-form controls. 25 Marks

Answer:

Algorithm / Logic

  1. Create an ASP.Net Web Form with fields for: Loan Amount, Interest Rate, Duration (in years)
  2. Use TextBox controls for input.
  3. Add a Button control to calculate Simple Interest.
  4. Add Label controls to display the result or validation messages.
  5. When the button is clicked, perform input validation:
  6. Check if any field is empty.
  7. Check if the values entered are numeric using IsNumeric() function.
  8. If all validations pass, calculate Simple Interest using the formula:SI=Loan Amount×Interest Rate×Duration100SI = \frac{\text{Loan Amount} \times \text{Interest Rate} \times \text{Duration}}{100}SI=100Loan Amount×Interest Rate×Duration​
  9. Display the calculated Simple Interest on the web form.
  10. If validation fails, display appropriate error messages.

Source Code

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SimpleInterestCalculator.Default" %>

<!DOCTYPE html>
<html lang="en">
<head runat="server">
    <meta charset="utf-8" />
    <title>Loan Simple Interest Calculator</title>
</head>
<body>
    <form id="form1" runat="server">
        <h2>Simple Interest Calculator</h2>

        <label for="txtLoanAmount">Loan Amount:</label>
        <asp:TextBox ID="txtLoanAmount" runat="server"></asp:TextBox><br />

        <label for="txtInterestRate">Interest Rate (%):</label>
        <asp:TextBox ID="txtInterestRate" runat="server"></asp:TextBox><br />

        <label for="txtDuration">Duration (years):</label>
        <asp:TextBox ID="txtDuration" runat="server"></asp:TextBox><br />

        <asp:Button ID="btnCalculate" runat="server" Text="Calculate Simple Interest" OnClick="btnCalculate_Click" /><br />

        <label for="lblResult">Calculated Simple Interest:</label>
        <asp:Label ID="lblResult" runat="server" Text="0.00"></asp:Label>
    </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Web.UI;

namespace SimpleInterestCalculator
{
    public partial class Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // No code needed for this example in Page_Load
        }

        protected void btnCalculate_Click(object sender, EventArgs e)
        {
            // Get the input values
            decimal loanAmount = decimal.Parse(txtLoanAmount.Text);
            decimal interestRate = decimal.Parse(txtInterestRate.Text);
            int duration = int.Parse(txtDuration.Text);

            // Calculate the simple interest
            decimal simpleInterest = (loanAmount * interestRate * duration) / 100;

            // Display the result
            lblResult.Text = simpleInterest.ToString("F2");
        }
    }
}

FAQ Section

1. Which ASP.Net controls are used in this program?

  • TextBox: To take user input
  • Button: To trigger calculation
  • Label: To display results or messages

2. Why is input validation important in web forms?

To prevent errors, ensure correct data types, and improve the reliability and user-friendliness of the application.

3. How do you check if a value is numeric in ASP.Net?

By using the IsNumeric() function in VB.Net.

4. What server-side language is used to perform calculations in ASP.Net?

VB.Net or C# can be used on the server side.

5. Why use Label controls instead of TextBox for results?

Label controls are read-only and prevent the user from changing the result.

Helpful Links

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top