Beginer question (or not?)

V

VR

Hi, I'm trying to set the focus to a specific control (a textBox named
txtName) in the page_Load event and here are two scnarios I've tryed to
build:

1. Setting the TabOrder of the controls in the WebForm
* if you set the txtName tabIndex property to 1 it's the first control
in the form to receive the focus by pressing TAB, but it do not receive the
focus when the page loads
* if you set this property to 0 it's the last control to receive the
focus

2. Setting the focus via script
* if I try to put some java/vb script on page like txtName.focus();
(java) or document.all("txtName").focus() (vbs) it says there's no object
with that name (the ID for the control is set to txtName and is unique
within the page)
* if I try to set it via code-behind I do not have the .focus() or
..setFocus() method available



If anyone has an idea about it, thanks a lot
Victor
 
H

Harry Simpson

Set focus, on page load

**********************************************************************

onload="javascript:document.all.mycontrol.focus();" attribute

to your body tag.

HTH

Harry
 
B

bruce barker

use the w3c syntax:

onload="javascript:document.getElementById('mycontrol').focus();"
onload="javascript:document.getElementsByName('mycontrol')[0].focus();"

or old school

onload="javascript:document.forms[0].elements['mycontrol'].focus();"

in any case the control names are case sensitive

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top