Change field value based on another field with Ajax and c#

485 Views Asked by At

I'm trying to create a page. It is very simple like when I change one textbox value, another one changes automatically without leaving the field. I used TextChanged event. But I have to leave the field to change another field value. Any help?

The aspx file :

<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

The aspx.cs file :

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    TextBox2.Text = TextBox1.Text;
}

I'm kinda newbie in aspx and c#. Please help me.

2

There are 2 best solutions below

0
On

use event 'OnkeyPress' not 'OnTextChanged'

1
On

This problem is best solved by KnockoutJS, AngularJS, jQuery, or simply Javascript