Click here to Skip to main content
15,915,163 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
1st textbox value 25
2nd textbox value 05 then i wanna bind thei Sum values in Third textbox without using Button ....
How to do this
Posted

Write your logic at TextChanged event it will work

like
C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
  {

textbox3.text=textbox1.text+textbox2.text;

  }


use type casting also
 
Share this answer
 
v2
Use following code :

C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
  {

if(textbox1.text.trim()!='' && textbox2.text.trim()!='')
textbox3.text=Convert.ToInt32(textbox1.text)+Convert.ToInt32(textbox2.text);

  }
protected void TextBox2_TextChanged(object sender, EventArgs e)
  {

if(textbox1.text.trim()!='' && textbox2.text.trim()!='')
textbox3.text=Convert.ToInt32(textbox1.text)+Convert.ToInt32(textbox2.text);

  }
 
Share this answer
 
Comments
phmani469 27-May-14 21:49pm    
what is the purpose of trim()......Where i want this trim method....
Bh@gyesh 28-May-14 0:37am    
trim() is used to delete extra spaces from end of text.
For eg. if you have entered "12 " in textbox1 then it will trim leading spaces from text and take only "12" in further consideration.
phmani469 28-May-14 2:02am    
thanks boss
<title>













///////////////////////////////jquery function to add and display

$(document).ready(function () {
$("#Text1,#Text2").keyup(function () {
$('#Text3').val(parseInt($('#Text1').val()) + parseInt($('#Text2').val()));
});
});

 
Share this answer
 
I would suggest you to use the Javascript/JQuery function to do this calculation as this calculation is very simple and can be calculated at client end easily without creating any overhead to server.

JavaScript
<script type="text/javascript">

 $(document).ready(function () { 

/* Please remember to replace the following in whole code given below  
[TextBox1ID] with the ID of textbox 1
[TextBox2ID] with the ID of textbox 2
[TextBox3ID] with the ID of textbox 3*/

 // Event Handler to execute when focus goes out of textbox 1 or textbox 2
 $("#[TextBox1ID], #[TextBox2ID]").blur(function () {

   // Assigning the value of both textboxes to variable for further calculations..
   var txtVal1=$("#[TextBox1ID]").val();
   var txtVal2=$("#[TextBox2ID]").val();

   //Here we are validating the values of first two textboxes to make sure that both have integer value...
   if(txtVal1!='' && !isNaN(txtVal1) && txtVal2!='' && !isNaN(txtVal2)) 
   {
     // Here we convert the value of first two textboxes into INT datatype and then performing the SUM operation and assigning it's value to third textbox. 
     $('#[TextBox3ID]').val(parseInt(txtVal1) + parseInt(txtVal2));
   }
 });
});
  
 </script>


I hope this will help you.. :)
 
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