Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET
Hello. I have made a calculator for five textboxes. The first two will subtract two numbers and the answer will be in the third textbox. The other three textboxes are adding three numbers and the answer is in the fourth textbox. I also have the textboxes with the answer in them to be greyed out. What is happening is that the answer fields can not be changed. If you put in the calculations and click the calculate button it will give you the answer but if you change the numbers and hit calculate button the answer will stay the same. What did I do wrong or what am I missing?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;

public partial class FinancialIndicatorsFormA : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void ButtonCalculate_Click(object sender, EventArgs e)
        int a = Convert.ToInt32(TextBoxTA.Text);
        int b = Convert.ToInt32(TextBoxTL.Text);
        TextBoxTNA.Text = Convert.ToString(a - b); 
    protected void ButtonCalculate2_Click(object sender, EventArgs e)
        int a = Convert.ToInt32(TextBoxNPRNA.Text);
        int b = Convert.ToInt32(TextBoxETRNA.Text);
        int c = Convert.ToInt32(TextBoxTUNA.Text);
        TextBoxTNA2.Text = Convert.ToString(a + b + c); 
Posted 23-May-13 2:31am
Edited 23-May-13 3:48am
Zafar Sultan at 23-May-13 10:00am
You "greyed" out the textboxes. Can you show how?
Kwesi Hopkins at 23-May-13 10:11am
Sure. In click on the textbox. Then go to properties. Enabled should be False and ReadOnly should be True. And there you go. Can you help me with my problem?
Zafar Sultan at 23-May-13 10:13am
Test after setting properties Enabled = true, ReadOnly = false. Does it work?
Kwesi Hopkins at 23-May-13 10:16am
Yes. you can't enter or edit anything in that box. Enabled = False, ReadOnly = True
Zafar Sultan at 23-May-13 10:22am
But if you change to Enabled = true and ReadOnly = false, it still behaves the same?
Kwesi Hopkins at 23-May-13 10:57am
If you don't want to grey it out you can just do Readonly = true. That way the calculation answer can appear but you can't edit it.
Zafar Sultan at 23-May-13 11:09am
You are not getting my point. If you change the properties like Enabled = true and ReadOnly = false for your "greyed out" textboxes, does you get the desired result? Or the output still remains the same after changing the values in the textboxes?
Kwesi Hopkins at 23-May-13 11:16am
Sorry. Yes I get the same output.
Kwesi Hopkins at 23-May-13 11:25am
I think I got it. I have a compare validator in place. I will have to double click into the answer box to highlight it and hit the backspace button to delete the answer then do my calculations again.
Amey K Bhatkar at 23-May-13 11:39am
If you put in the calculations and click the calculate button it will give you the answer but if you change the numbers and hit calculate button the answer will stay the same. Is this mean that you just want answer at first time only then it will be better you make then read-only after you hit on the calculate button.
Kwesi Hopkins at 23-May-13 11:52am
Ok. What I did was to do the first calculations. The first changes every time you enter a different number and click calculate button. the second calculate is what was getting to me because I put a compare validator to compare the answers. Once the answers are the same I can go to the next field, if not then I would have to change something. I had to change the first calculation before I change the second because of the compare validator.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Actually, doing all this makes no sense at all, because JavaScript already can execute any text which is entered by a user, as a script, and show the result. This is done by the function eval. That's nearly all you need. If you want, check up how my calculator works:[^].
Kwesi Hopkins at 23-May-13 9:28am
Ok. I don't know Java Script. I just need to know how to get my answers to change when I enter in different one to calculate.
Sergey Alexandrovich Kryukov at 23-May-13 12:45pm
What is Java Script? There is no such thing. Java is not a scripting language. But JavaScript — you just have to know, this is not an option. Anyway, I don't see a reason to suggest you any alternatives, sorry. I don't thin anything else makes practical sense in Web applications, for such a simple thing as a calculator. Sending HTTP request/responses back and forth for no good purpose is not fair to traffic. :-) —SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
0 Shai Vashdi 339
1 Sergey Alexandrovich Kryukov 285
2 OriginalGriff 280
3 Peter Leow 171
4 Abhinav S 168
0 Sergey Alexandrovich Kryukov 8,979
1 OriginalGriff 5,280
2 Peter Leow 4,010
3 Maciej Los 3,535
4 Abhinav S 3,263

Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid