468,505 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Changing control focus programmatically

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.


Nov 17 '05 #1
2 2186
You can do this only by javascript.
Ivan
-----Original Message-----
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 locatedin the middle of my form.

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

Any hints/leads are appreciated. Thank you.


.

Nov 17 '05 #2
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
"Elliot M. Rodriguez" <elliotmrodriguezatnospamhotmail.com> wrote in message
news:#$**************@TK2MSFTNGP09.phx.gbl...
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.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by tshad | last post: by
4 posts views Thread by Jon Slaughter | last post: by
1 post views Thread by Axeman | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.