473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Setting focus to another User Control

I have a page with several user controls on it.
Some of the UC's have multiple text boxes that get auto-populated via
the OnTextChanged event. When this happens, I lose my focus (where the
blinking cursor is).

I have some SetFocus JavaScript that works from a page event, but I'm
not sure what I'd need to change to make it work from within a UC and
have it set focus to another control inside another UC. To complicate
this further, I'd like to be able to make the destination control that
receives focus variable, so that if the controls are re-ordered, the
next one down gets focus regardless of what is is.

Can this be done? Below is the JavaScript that works from a page event,
but I'm having trouble with it because I'm not even sure if I can find
my other controls from within a UC to pass this a non-null control.

----
Public Shared Sub SetInitialFocus(ByVal ctrl As Control)
Dim s As String
s = "<SCRIPT LANGUAGE='JavaScript'> function SetInitialFocus(){
document."
Dim p As Control = ctrl.Parent
While Not TypeOf p Is System.Web.UI.HtmlControls.HtmlForm
p = p.Parent
End While
s = s & (p.ClientID)
s = s & "['"
s = s & ctrl.UniqueID
s = s & "'].focus(); }"
s = s & "window.onload = SetInitialFocus; </SCRIPT>"
ctrl.Page.RegisterClientScriptBlock("InitialFocus" , s.ToString())
End Sub

----
So to use this from Page_Load, I do somehting like:
----
Dim txtAddress As TextBox =
FindControl("UC1").FindControl("TextBox1")
If Not IsNothing(txtAddress) Then SetInitialFocus(txtAddress)

Hope this makes sense. Thanks!

Matt
Nov 19 '05 #1
0 1424

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function...
4
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several...
2
by: Sridhar | last post by:
Hi, I have a question. I have created a user control which contains a textbox and a button. we will enter some search word in the textbox and hit the button. Then we will get a pop-up with the...
7
by: Dave Booker | last post by:
I am using a WebBrowser object in my .NET 2.0 application, but it is not shown to the user. Every time a timer event triggers it to perform a m_WebBrowser.Navigate() I get that classic IE 'click'...
4
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the...
0
by: RKT | last post by:
I have a DataGridView bound to an MS Access table. This is a single- user application. When the User is adding or editing a row, the User may click on a Control elsewhere. That Control has context...
3
by: kelvin.koogan | last post by:
I have a number of controls on a tab page. I want to validate them all when the user tries to leave the tab. I then want to highlight the first control which fails validation. How can I do this? I...
2
by: angi35 | last post by:
I hope this is an easy question for someone out there. In Access 2000…I have a MainForm with a tab control (MAIN TABS) with 7 tabs. Within each tab is a SubForm. Within each SubForm is a tab...
3
by: zacks | last post by:
I am working on an application that has a UI that supports multiuple functions by means of a group of "plug ins". Each plugin is a class library. Each plugin contains a User Control that defines...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.