Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET
I have two textboxes.I want to change 2nd textbox value according to whatever i entered in 1st textbox..means suppose i enter 5 in first text and then value 50 should come in 2nd textbox. plz help me?
Posted 16-Feb-13 2:09am
Nilesh Patil Kolhapur at 16-Feb-13 7:49am
you should try Sandeep Mewara's answer
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You need to work on TextBox1_TextChanged event.
protected void TextBox1_TextChanged(object sender,EventArgs e)
int example=Convert.ToInt32(Textbox1.Text*10);
Change the AutoPostBack property As true for TextBox1.

It will display.
TextBox1 TextBox2
3-----------> 30
4-----------> 40
5-----------> 50

Hope it will help you.
Sandeep Mewara at 16-Feb-13 8:22am
Why to do all these when one can achieve it on client side.
If OP was really asking for Server side code, then you have my vote too. But, in that case, OP is really a beginner and should read some book before starting to code.
Gunjan Bhasin at 16-Feb-13 13:35pm
Whats wrong in the code?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Last time, please try such small things by yourself instead of asking questions here. You need to learn and make some effort.
Steps for your thing:
1. Define a onblur or onfocusout event for the textbox1 (if server control then add through attributes)
2. Define the related method in JavaScript
3. In this method, get the value of textbox1 and then based on it set the value in textbox2
You might need to know:
How to access textbox value in JS:
How to add attribute via code:
textbox1.Attributes.Add("onblur","javascript: GetT1ValueAndSetT2(this);");
So overall,
<asp:TextBox ID="txtValue1" runat="server" ></asp:TextBox>
<asp:TextBox ID="txtValue2" runat="server"  ></asp:TextBox>
and Javascript
<script type="text/javascript">
  function GetT1ValueAndSetT2(txtValue1)
Try now.
Nilesh Patil Kolhapur at 16-Feb-13 8:11am
sir sorry but i tried like <asp:TextBox ID="txtValue2" runat="server" onblur="GetT1ValueAndSetT2(this)" >
and its working fine
sorry if i am wrong....
Sandeep Mewara at 16-Feb-13 8:19am
Is it? onblur event on server textbox? From when?
If it's an input type textbox, it would but with ASP.NET Textbox control?

BTW, it's ok. You tried to help more, it's just that the addition didn't looked right to me. Keep sharing others and keep good work up. :)
Nilesh Patil Kolhapur at 23-Feb-13 4:25am
Yes sir u can try. just write client side event like onkeypress directly in server side control script.
try this
Shahriar Iqbal Chowdhury/Galib at 16-Feb-13 8:39am
good answer @sandeep, plain and simple.
Sandeep Mewara at 16-Feb-13 8:41am
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You can use jquery to solve the issue. Try this solution below,
<script  type="text/javascript" src=""></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("input[type='text']:eq(0)").keyup(function () {
            var txtVal = $("input[type='text']:eq(0)").val();
            var calculated = parseInt(txtVal) * 10;
And here is your TextBox's
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
Hope this will help.

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

  Print Answers RSS
0 Zoltán Zörgő 200
1 Sergey Alexandrovich Kryukov 160
2 Peter Leow 90
3 Ramza360 51
4 Arkadeep De 50
0 Zoltán Zörgő 80
1 the other paul 23
2 Shmuel Zang 10
3 Aarti Meswania 5
4 Member 11389991 -2

Advertise | Privacy | Mobile
Web02 | 2.8.150129.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100