Changing control focus programmatically

  • Thread starter Thread starter Elliot M. Rodriguez
  • Start date Start date
E

Elliot M. Rodriguez

Is it possible to change a control's focus at runtime? I'm sure you can....

I have a form with 2 textbox controls that cause postbacks. They are located
in the middle of my form.

When a postback occurs, no control has the focus. I would like it to be so
that the control that causes the postback keeps the focus. Since I have 2
controls that potentally need to retain focus, using Javascript in this case
is a PIA.

Any hints/leads are appreciated. Thank you.
 
Hi Elliot,

Using JS To accomplish this isn't that big of a deal. In your TextChanged
event, add:
RegisterStartUpScript("scriptname", _
"<script>" & _
"document.getElementByID('" & _
MyTextBox.UniqueID & "').focus();" & _
"</script>")

You could also wrap that in a function where all you pass is the control to
get focus ...

-- Alex Papadimoulis
 
Back
Top