473,769 Members | 8,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Focus on control in webform

How do I set focus on a textbox in a web-form?
regards
Rehiaa
Nov 16 '05 #1
3 2382
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.richTextBo x2.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.getEle mentById('First Name').focus();

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

public void SetFocus(Contro l focusControl)
{
string clientID = focusControl.Cl ientID;
System.Text.Str ingBuilder script = new
System.Text.Str ingBuilder();
script.Append(@ "<script language='javas cript'>");
script.Append(@ "if(document.ge tElementById('" + clientID +
@"')){document. getElementById( '" + clientID + @"').focus();}" );
script.Append(@ "</script>");

RegisterStartup Script("setFocu s", script.ToString ());
}

Then all you have to do is call it:

SetFocus(this.F irstName);

David Barkol
www.neudesic.com

Nov 16 '05 #3
Page.RegisterSt artupScript("fo cusScript", @"<script>

function setFocus(elemen tID) {

element = window.document .getElementById (elementID);

element.focus() ;

}

setFocus('txt1' );

</script>");

HTH

DalePres

MCAD, MCDBA, MCSE

"reidarT" <re****@eivon.n o> wrote in message
news:OB******** *****@TK2MSFTNG P14.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
1016
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 PRNUM. When a user double clicks on a PRNUM in the mrGrid I want to be able to set the focus on the same number in the PRNUM column in the prGrid. Is this possible and how is it accomplished? Thanks,
2
1009
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 click. The problem is that I have buttons in a user control (its a navigation control) across the top of the page. So the button in the left upper corner always has focus, and that is not the button that the customer wants focused. Is there...
5
9751
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 this user control inside another webform. The webform has a "Next" button which is initially disabled. When the user control successfully adds a record I want the Next button on the webform to get enabled. Checking if the record was added...
2
1070
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 have any effect. Any idea on how I could do that? Thanks Mike
5
1365
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
2271
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 called focus, that it would replace the .setfocus method of VB6. But I don't understand the example. Does anyone have an example ?
1
1791
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(); sb.Append("\r\n<script language='JavaScript'>\r\n"); sb.Append("<!--\r\n"); sb.Append("function SetFocus()\r\n");
5
2040
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 information and one that resets the form... The second on, the reset button, i would like to set focus back to the first textbox on the form. I already have an onload in my body, which sets the
3
2025
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 text box, I want to automatically fill in the second text box with the information from the first text box. I just can't seem to find an event handler for when the control gains/loses focus. -StinkyDuck
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
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
10049
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
9998
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
8876
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...
0
6675
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();...
1
3967
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
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.