473,659 Members | 2,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set focus to a control on Page_Load

Hi all,

Can anyone tell me how to set focus to particular control on Page_Load() in
ASP.Net? I could not find any Control.Focus() method.

Thanks for any help!

Tedmond

Feb 13 '06 #1
3 1473
Howdy,

-- BEGIN CODE --

public static void SetFocus(Contro l control)
{
System.Text.Str ingBuilder script = new System.Text.Str ingBuilder();

script.Append(" \r\n<script language='JavaS cript'>\r\n");
script.Append(" <!--\r\n");
script.Append(" function OnWindowLoad()\ r\n");
script.Append(" {\r\n");
script.Append(" \tdocument.");

Control parent = control.Parent;

// get parent form id
while (!(parent is System.Web.UI.H tmlControls.Htm lForm))
parent = parent.Parent;

script.Append(p arent.ClientID) ;
script.Append("['");
script.Append(c ontrol.UniqueID );
script.Append(" '].focus();\r\n") ;
script.Append(" }\r\n");
script.Append(" window.onload = OnWindowLoad;\r \n");
script.Append("// -->\r\n");
script.Append(" </script>");

control.Page.Re gisterClientScr iptBlock("SetFo cusScript",
script.ToString ());
}

-- END CODE --

--
Milosz Skalecki
MCP, MCAD
"Tedmond" wrote:
Hi all,

Can anyone tell me how to set focus to particular control on Page_Load() in
ASP.Net? I could not find any Control.Focus() method.

Thanks for any help!

Tedmond

Feb 13 '06 #2
If you're using 1.x, you have to build your own using Javascript. The Focus
method is available in 2.0.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"Tedmond" <Te*****@discus sions.microsoft .com> wrote in message
news:55******** *************** ***********@mic rosoft.com...
Hi all,

Can anyone tell me how to set focus to particular control on Page_Load()
in
ASP.Net? I could not find any Control.Focus() method.

Thanks for any help!

Tedmond

Feb 13 '06 #3
Hi Tedmond,

Set the TabIndex of the control (Which needs focus) to 0, and set all
the remaining controls TabIndex to consequent numbers.

This worked for me.

Cheers,
Kris

Feb 13 '06 #4

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

Similar topics

1
1668
by: Paul Tsai | last post by:
Dear All, I used csharp web form to develop my company web application, and my question is how shuld I do if I want to focus on my textbox(ex. like Java Script form.txtID.focus()). Thanks !! Sincerely yous, Paul
5
1359
by: Glenn T. Kitchen | last post by:
Hello All, Does anyone know how to set the focus to a textbox control on Page_Load? Thank you, Glenn
3
4621
by: Kurt Schroeder | last post by:
I'm setting focus depenting upon which field has changed value. I'm doing this with the following: Page.RegisterStartupScript("SetFocus", "<script language=""Jscript"" > document.getElementById(""txtCity"").focus(); </Script>"). This is being called on the textChanged event for textboxes. for city it goes to state for state it goes to zip, ... It works, but is this the correct way to do this or should this be a seties of if then else's in...
0
1437
by: MattB | last post by:
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...
1
2047
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
1
5133
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
4
4047
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 user looking at window A clicks the "open window B" link, I want
8
6896
by: Mel | last post by:
I have several text boxes and drop-down lists in an AJAX Update Panel. All user inputs have the Postback property set to True. After I type something in the first input entry and press the "Tab" key how can I set the focus to the next box after the postback? Please help! Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
11
3920
by: slinky | last post by:
I'm trying to simply set the focus of "txtUserName" upon opening this login form. I put in some Javascript but it is not working. Any ideas? Thanks! <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Login.aspx.vb" Inherits="Forsyth.HR_ReportingTool.UI.Login" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD>
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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
8747
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...
1
8528
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
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...
1
6179
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
4175
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...
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.