Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Frnds,

I have Three Textboxes and Submit button on my webpage as....

TxtFirstNumber
TxtSecondNumber
TxtAnswer

BtnSubmit


Adding two textboxes values and displaying in another textbox on submit button click
-------------------------------------------------------------------------------------

When I enter 10 in firstTextbox and another 10 in second Textbox the answer should be displayed in another textbox as 20.

Please can you help me.

Thanks.
Posted
Comments
[no name] 24-Sep-13 13:37pm    
Help you with what? You would have to ask a question or describe some sort of a problem before you can expect to get any help. What have you tried?

Try This One :


TxtAnswer.Text = (Convert.ToDecimal(TxtFirstNumber.Text) + Convert.ToDecimal(TxtSecondNumber.Text)).ToString();
 
Share this answer
 
int firstNum = Convert.ToInt32(TxtFirstNumber.Text);
int secondNum = Convert.ToInt32(TxtSecondNumber.Text);
TxtAnswer.Text = firstNum + SecondNum;
 
Share this answer
 
Comments
Diana Tsax 7-Oct-13 7:51am    
int firstNum = Convert.ToInt32(TxtFirstNumber.Text);
int secondNum = Convert.ToInt32(TxtSecondNumber.Text);
TxtAnswer.Text = (firstNum + SecondNum).ToString();
Convert it to string!!!!!!!!!!!!!!!!!!!!!!
C#
var result = Convert.ToDouble(txtFirstNumber.Text) + Convert.ToDouble(txtSecondNumber.Text);
txtAnswer.text = result.ToString();


Of course it is up to you to do any error handling, since text boxes accept alphanumeric characters as well as numeric ones.
 
Share this answer
 
Comments
Abhinav Gauniyal 24-Sep-13 14:31pm    
i too think he was facing the problem of conversion of String type to some numeric +1
try this :

use javascript in client side for not allowing them to use alphabets in those textboxes

TxtAnswer.Text = Convert.ToString(Convert.ToDouble(TxtFirstNumber.Text)+
Convert.ToDouble(TxtSecondNumber.Text));
 
Share this answer
 
v2
after btn click

txt3.text=Convert.ToString((Convert.ToDecimal(txt1.text)+Convert.ToDecimal(Txt2.text)))

or u can also used a variable to put the text.box data and then apply the above step
 
Share this answer
 

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