Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to add two textbox value on textbox keypress event in web application?
Posted
Updated 1-Nov-12 3:49am
v3
Comments
a1mimo 1-Nov-12 8:31am    
A further explanation would be good if you looking for an answer

To resolve your problem follow below step.

step 1: Create java script function

function txtOnkeypress()
{
// apply your logic here..
}

For example:
XML
<script type="text/javascript">
        function txtOnKeyPress(txt1)
         {
            if (txt1 != 'undefined') 
            {
                 txt2 = document.getElementById('<%=TextBox2.ClientId               %>');
                 txt2.value = txt1.value;

            }
         }
    </script>




step 2: call javascript function on textbox key press event.


onkeyPress = txtOnkeypress()

For example:

XML
<asp:TextBox ID="texbox1" runat="server" onkeydown="txtOnKeyPress(this);" ></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>




Thanks
Vipul patel
 
Share this answer
 
v5
Comments
fjdiewornncalwe 1-Nov-12 14:20pm    
I would suggest you remove the spam link from your posts before you get reported too many times for it.
C#
protected void textbox1_KeyPress(Object sender,KeyPressEventArgs e)
{
   if(e.KeyChar==(char)Keys.Tab)
   {
      Keybox4.Focus();
   }

}


Addionally MultiLine property set to true, and AcceptsTab also set to true.
 
Share this answer
 
v2
Comments
Sanjay K. Gupta 1-Nov-12 8:43am    
The solution may asked for ASP.NET. Your code shows C#.NET window application.
fjdiewornncalwe 1-Nov-12 9:52am    
Can ASP.NET not get written with C# in the back end? Your downvote on this answer is simply wrong as the answer is correct. The OP has not specified his code behind language.
Sanjay K. Gupta 1-Nov-12 9:55am    
He has specified the Tag.
fjdiewornncalwe 1-Nov-12 9:59am    
No, he has not. He has specified ASP.NET, not the language of code behind.
Sanjay K. Gupta 1-Nov-12 10:00am    
It is enough.
C#
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
        (e.KeyChar != '.'))
    {
            e.Handled = true;
    }

    // only allow one decimal point
    if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
    {
        e.Handled = true;
    }
}
 
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