Click here to Skip to main content
15,889,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have two TextBoxes. Both are dynamically created and width of both are set dynamically. So problem is that when I enter text in first textbox and it gets its end then remaining text should be entered in another textbox automatically.
For example while writing name in cheque, when first line is fulled then we move to another line given below it.

Thanks.
Posted

You need to use javascript for it. Track the number of characters in first textbox. The moment it crosses the fixed number(lets say 50), set the focus on next textbox.

You can use any one of the events to track the no. of character typed:
onchange, onBlurr, onFocusOut, onKeyUp....
 
Share this answer
 
Try something like this: It checks every time a user presses a key if it checks if it exceeds the textbox and if so if focusses the next one. Not sure if this code will work 100% on ASP.NET but I think it should give atleast a good idea on how this can be done.

void textBox1_KeyDown(object sender, KeyEventArgs e)
{

Size textSize = System.Windows.Forms.TextRenderer.MeasureText(textBox1.Text, textBox1.Font, textBox1.Size, TextFormatFlags.Default);

if(textSize.Width >= textBox1.Width)
{
  textBox2.Focus();
}

}
 
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