473,473 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2408
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: tshad | last post by:
Is there a way during Page_Load to change or add an attribute to the Body tag? I want to be able to change the onLoad body attribute to do a focus on one of my text boxes, such as: ...
2
by: Tedmond | last post by:
Dear all, How can I programmatically focus to next control in a form by tabIndex order? Tedmond
2
by: egholm | last post by:
Hey I'm creating some textboxes dynamically. Everytime a textchange event happens in one of these textboxes, I want the cursor to be active in the next textbox. What do I write in my textchanged...
3
by: vivela | last post by:
hi, I hope you could help me out on this one,cause I have been trying for 4 days to solve it,but couldn't quite get it right: I have an ASP textbox that should change the value in a dropdownlist....
4
by: MLH | last post by:
Short of inserting code similar to that shown below in the OnGotFocus event property for each and every control on the form, is there a form-level event I could monitor firing similar code. I...
4
by: Jon Slaughter | last post by:
Is there any method to temporarily disable focus changing?(I assume only method is tab or mouse?) This problem has been tieing me up for a while and nothing seems to work. The only thing that I...
9
by: Zytan | last post by:
http://msdn2.microsoft.com/en-us/system.windows.forms.control.focus(VS.80).aspx this page says: "Focus is a low-level method intended primarily for custom control authors. Instead, application...
1
by: Axeman | last post by:
I have an AJAX enabled web form with several data-filled GridView controls. The users accessing this web app will navigate the site via touch-screen monitors (i.e.: no mouse). As a result, I need...
3
by: jimatqsi | last post by:
I'm having trouble changing the focus from form to form. I've got a big form with two smaller forms. The main form takes the left 1/3 of the screen, subform1 the upper right, and subform2 the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.