473,399 Members | 4,192 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,399 software developers and data experts.

Focus on control in webform

How do I set focus on a textbox in a web-form?
regards
Rehiaa
Nov 16 '05 #1
3 2359
I tried this with two rich text boxes. When the program is started, it
would automatically give focus to richTextBox1. So in order to give
focus to richTextBox2, in the form load method, i called the following:

this.richTextBox2.Select();

It worked for me.

reidarT wrote:
How do I set focus on a textbox in a web-form?
regards
Rehiaa


Nov 16 '05 #2
In javascript:

document.getElementById('FirstName').focus();

If you wanted to do this in your server side code then you need a
procedure that registers this script:

public void SetFocus(Control focusControl)
{
string clientID = focusControl.ClientID;
System.Text.StringBuilder script = new
System.Text.StringBuilder();
script.Append(@"<script language='javascript'>");
script.Append(@"if(document.getElementById('" + clientID +
@"')){document.getElementById('" + clientID + @"').focus();}");
script.Append(@"</script>");

RegisterStartupScript("setFocus", script.ToString());
}

Then all you have to do is call it:

SetFocus(this.FirstName);

David Barkol
www.neudesic.com

Nov 16 '05 #3
Page.RegisterStartupScript("focusScript", @"<script>

function setFocus(elementID) {

element = window.document.getElementById(elementID);

element.focus();

}

setFocus('txt1');

</script>");

HTH

DalePres

MCAD, MCDBA, MCSE

"reidarT" <re****@eivon.no> wrote in message
news:OB*************@TK2MSFTNGP14.phx.gbl...
How do I set focus on a textbox in a web-form?
regards
Rehiaa

Nov 16 '05 #4

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

Similar topics

0
by: Dave Bailey | last post by:
I have a DataGrid control on a WebForm called mrGrid. In this grid is a column named PRNUM. In addition there is another DataGrid on this WebForm named prGrid. It alson contains a column named...
2
by: David Cho | last post by:
After the user fills out the webform, my customer would like a default button on the form to have focus, so that all the user has to do is press <enter> as opposed to having to take the cursor and...
5
by: George Durzi | last post by:
I have a simple user control with a text box and a submit button. When the user enters some text into the textbox and clicks the submit button, a record is created in the database. I'm using...
2
by: Mike | last post by:
Hi, I have a webform with two textboxes and two buttons. I would like to set the focus to the first textbox when the page is displayed. I tried to change the TabIndex, but apparently, it does not...
5
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
2
by: gabriel Morgulis | last post by:
How can I set the focus on a particular control in a webform? IE: If I have 3 textboxs controls on my webform and I want to be on the middleone , how can I do it? I saw that there is a method...
1
by: reidarT | last post by:
I have a webform and found some code where I understand some of it, but not all The code is as follows public static void SetFocus(Control control) { StringBuilder sb = new StringBuilder(); ...
5
by: Finn Stampe Mikkelsen | last post by:
Hi How can i set a focus to a textbox in my codebehind page?? I have this WebForm, that takes information from a user and 2 buttons on the form. One that takes action on the entered...
3
by: StinkyDuck | last post by:
Is there a way to detect when a control gains focus on a webform? Say I have two text boxes. After the user types in information on the first text box and hits the tab key or clicks on the second...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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,...
0
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...

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.