473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing control focus programmaticall y

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 2427
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:
RegisterStartUp Script("scriptn ame", _
"<script>" & _
"document.getEl ementByID('" & _
MyTextBox.Uniqu eID & "').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" <elliotmrodrigu ezatnospamhotma il.com> wrote in message
news:#$******** ******@TK2MSFTN GP09.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
2040
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: onLoad="document.forms.txtLogon.focus();" The problem is I have my <body> in an include file and want to set the onLoad attribute during Page_Load time.
2
7913
by: Tedmond | last post by:
Dear all, How can I programmatically focus to next control in a form by tabIndex order? Tedmond
2
2739
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 event to make this happen? I hope You can help me. Jacob
3
2814
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. this happens,but the problem is with the validation of the ddl.it has a requiredfieldvalidator,and the error message disapears only if i select a value from the dropdownlist,even though it should also disapear when I write a valid name in the...
4
1242
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 don't want to sprinkle code all over the form if I can do what I want in a single place. Dim ctlCurrentControl As Control Dim strControlName As String Set ctlCurrentControl = Screen.ActiveControl
4
6628
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 *know* will work is to disable all tab stops on all controls. This brute force method doesn't seem like a good idea though. What I wanted to do was take control the control enter/leave and mouse enter/leave and "switch back" the focus when it is...
9
18001
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 programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms." I am trying to give a Numeric UpDown control focus. Only Focus() works. But this says to not use it.
1
11599
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 an easy way for them to scroll the GridViews when the data is not visible. I want them to click on a button, which will then accordingly scroll the grid up or down. I have tried all the various combinations of the suggestions that I could find: ...
3
8565
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 lower right portion of the screen. I want the user to be able to advance to subform1 with a control/M and to subform2 with a control/B keystroke. I used this code: Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) ' control/M...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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 we have to send another system
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.