Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
C#
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
Updated 23-May-13 3:48am
v2
Comments
Zafar Sultan 23-May-13 10:00am    
You "greyed" out the textboxes. Can you show how?
Computer Wiz99 23-May-13 10:11am    
Sure. In asp.net 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 23-May-13 10:13am    
Test after setting properties Enabled = true, ReadOnly = false. Does it work?
Computer Wiz99 23-May-13 10:16am    
Yes. you can't enter or edit anything in that box. Enabled = False, ReadOnly = True
Zafar Sultan 23-May-13 10:22am    
But if you change to Enabled = true and ReadOnly = false, it still behaves the same?

1 solution

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: http://sakryukov.org/freeware/calculator/[^].

—SA
 
Share this answer
 
Comments
Computer Wiz99 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900