Changing control focus programmatically

  • Thread starter Elliot M. Rodriguez
  • 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.
 
A

Alex Papadimoulis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top