Set focus on textbox after postback.
Posted
by Niike2
on Stack Overflow
See other posts from Stack Overflow
or by Niike2
Published on 2010-04-22T12:36:34Z
Indexed on
2010/04/23
6:33 UTC
Read the original article
Hit count: 522
I have a search page with 3 TextBoxes that users can filter a search with.
I have put the focus on the TextBox that contains text. If more than one contains text just focus on last TextBox.
private void SetFocusOnTextBox(ControlCollection ctrlCollection)
{
foreach (Control ctrl in ctrlCollection)
{
if (ctrl.GetType() == typeof(TextBox))
{
if (((TextBox)ctrl).Text != string.Empty)
{
SetFocus(ctrl);
}
}
}
}
After the code runs and a user searches, the focus comes to the beginning of the TextBox, not the end where it would be presumed. How to put insert marked at the end of that TextBox?
© Stack Overflow or respective owner