473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How can I properly get my 'Calculate' button to calculate the total and discount?

74 64KB
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. namespace XEx02Quotation
  9. {
  10.     public partial class Default : System.Web.UI.Page
  11.     {
  12.         protected void Page_Load(object sender, EventArgs e)
  13.         {
  14.  
  15.         }
  16.  
  17.         protected void Button1_Click(object sender, EventArgs e)
  18.         {
  19.             if (IsValid)
  20.             {
  21.                 int SalesPrice = Convert.ToInt32(TextBox1.Text);
  22.                 double DiscountPercentage= Convert.ToDouble(TextBox2.Text);
  23.                 double discountAmount = Convert.ToDouble(Label1.Text);
  24.                 double TotalPrice = Convert.ToDouble(Label2.Text);
  25.                 double discountValue = this.CalculateDiscountValue(SalesPrice, DiscountPercentage, discountAmount);
  26.                 double TotalValue = this.TotalPriceCalculate(TotalPrice, SalesPrice, discountAmount);
  27.                 Label1.Text = discountValue.ToString("c");
  28.                 Label2.Text = TotalPrice.ToString("c"); 
  29.  
  30.             }
  31.         }
  32.         protected double CalculateDiscountValue(int SalesPrice, double DiscountPercentage, double discountAmount)
  33.         {
  34.             discountAmount = SalesPrice * DiscountPercentage;
  35.             return discountAmount; 
  36.         }
  37.  
  38.         protected double TotalPriceCalculate(double TotalPrice, int SalesPrice, double discountAmount)
  39.         {
  40.             TotalPrice = SalesPrice - discountAmount;
  41.             return TotalPrice; 
  42.         }
  43.  
  44.  
  45.     }
  46.  
  47. }
  48.  


Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="XEx02Quotation.Default" %>
  2.  
  3. <!DOCTYPE html>
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7.     <title>Price quotation</title>
  8.     <style type="text/css">
  9.         .auto-style1 {
  10.             width: 54%;
  11.             height: 213px;
  12.         }
  13.         .auto-style15 {
  14.             width: 114px;
  15.             height: 23px;
  16.         }
  17.         .auto-style16 {
  18.             width: 114px;
  19.         }
  20.         .auto-style17 {
  21.             width: 114px;
  22.             height: 28px;
  23.         }
  24.         .auto-style18 {
  25.             width: 193px;
  26.             height: 23px;
  27.         }
  28.         .auto-style20 {
  29.             width: 193px;
  30.             height: 28px;
  31.         }
  32.         .auto-style21 {
  33.             width: 193px;
  34.         }
  35.         .auto-style22 {
  36.             margin-left: 12px;
  37.         }
  38.         .auto-style23 {
  39.             margin-left: 16px;
  40.         }
  41.         .auto-style25 {
  42.             width: 193px;
  43.             height: 5px;
  44.         }
  45.         .auto-style26 {
  46.             width: 114px;
  47.             height: 5px;
  48.         }
  49.         .auto-style27 {
  50.             width: 143px;
  51.             height: 23px;
  52.         }
  53.         .auto-style28 {
  54.             width: 143px;
  55.             height: 5px;
  56.         }
  57.         .auto-style29 {
  58.             width: 143px;
  59.         }
  60.         .auto-style30 {
  61.             width: 143px;
  62.             height: 28px;
  63.         }
  64.         .auto-style31 {
  65.             width: 143px;
  66.             height: 25px;
  67.         }
  68.         .auto-style32 {
  69.             width: 193px;
  70.             height: 25px;
  71.         }
  72.         .auto-style33 {
  73.             width: 114px;
  74.             height: 25px;
  75.         }
  76.     </style>
  77. </head>
  78. <body>
  79.  
  80.     <form id="form1" runat="server">
  81.  
  82.         <h1>Price quotation</h1>
  83.  
  84.         <br />
  85.         <br />
  86.         <table class="auto-style1">
  87.             <tr>
  88.                 <td class="auto-style27">Sales Price</td>
  89.                 <td class="auto-style18">
  90.                     <asp:TextBox ID="TextBox1" runat="server" CssClass="auto-style23" Width="173px" Font-Bold="True"></asp:TextBox>
  91.                 </td>
  92.                 <td class="auto-style15"></td>
  93.             </tr>
  94.             <tr>
  95.                 <td class="auto-style27"></td>
  96.                 <td class="auto-style18"></td>
  97.                 <td class="auto-style15"></td>
  98.             </tr>
  99.             <tr>
  100.                 <td class="auto-style27">Discount percent</td>
  101.                 <td class="auto-style18">
  102.                     <asp:TextBox ID="TextBox2" runat="server" CssClass="auto-style22" Width="169px"></asp:TextBox>
  103.                 </td>
  104.                 <td class="auto-style15"></td>
  105.             </tr>
  106.             <tr>
  107.                 <td class="auto-style28">Discount amount</td>
  108.                 <td class="auto-style25">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Label"></asp:Label>
  109.                 </td>
  110.                 <td class="auto-style26"></td>
  111.             </tr>
  112.             <tr>
  113.                 <td class="auto-style27"></td>
  114.                 <td class="auto-style18"></td>
  115.                 <td class="auto-style15"></td>
  116.             </tr>
  117.             <tr>
  118.                 <td class="auto-style30">Total price</td>
  119.                 <td class="auto-style20">
  120.                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  121.                     <asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Label"></asp:Label>
  122.                 </td>
  123.                 <td class="auto-style17"></td>
  124.             </tr>
  125.             <tr>
  126.                 <td class="auto-style31">
  127.                     </td>
  128.                 <td class="auto-style32"></td>
  129.                 <td class="auto-style33"></td>
  130.             </tr>
  131.             <tr>
  132.                 <td class="auto-style29">
  133.                     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Calculate" Width="90px" />
  134.                 </td>
  135.                 <td class="auto-style21">&nbsp;</td>
  136.                 <td class="auto-style16">&nbsp;</td>
  137.             </tr>
  138.         </table>
  139.  
  140.     </form>
  141.  
  142. </body>
  143. </html>
  144.  
Hello Everyone,
I have created an ASP.NET 4.6 Web Form in a web application and I using C# to implement the functionality of some of the web server controls, but I am having trouble understanding why when I hit the 'Calculate' button, it doesn't calculate the discount amount and total price in the respective labels in bold when I enter sales price and discount percentage in the textboxes. Here is my Default.aspx code and Default.aspx.cs (C#) code. What I am doing wrong?
Sep 3 '17 #1
0 2550

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Jurek | last post by:
I have 10+ experience in C/C++ - mostly automation and graphics. I have never written any business apps though. Recently I've been asked to write a simple report that would calculate sales...
0
by: Simon Gare | last post by:
Hi, I need to calculate a total based on fields in a repeat region, these values are stored in an SQL db, all are numeric and written in ASP. fields are TOTAL_COST VAT ...
8
by: jimmyg123 | last post by:
Hi, I'm trying to do something similar. This is my javascript <script type='text/javascript'> function totalise(price,total) { var qty = window.document.getElementById('qty').value; var...
2
by: 06mca30 | last post by:
How to calculate total no of hits for my home page?
1
by: beena | last post by:
Hi All, Is there a way to calculate the maximum total memory ever used by the instance? Is db2mtrk the answer ... especially the high watermark option..... If I add up all the values......Will ...
3
by: John Torres | last post by:
how do you calculate total time hours? I have sub total hours for each day and I've been trying to total all the hours. I'm getting odd numbers. Thanks. John
4
by: Jackwaters | last post by:
I have a problem in that I have an arrayList called pizzaOrders which contains a number of pizza orders. The pizza orders contain information like names, addresses, total price for orders and the...
2
by: mroberts50 | last post by:
I have to develop a programm for a race that is suppose to put the runners in first, second and third place. Everything works except my calculate button this is my code.Forgive me I am very new to...
2
by: idealsavran | last post by:
hello.. How can I calculate the total of pages for all file(pdf,word,excel,txt...) types in a directory with c#? please... help!!!
7
by: irsmalik | last post by:
Hi friends I have StartDate and EndDate at my form. I have found a Function GetElapsedTime(interval) which calculate hours & minutes when I give StartDate and Enddate. At my form TimeSpent is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.