PDA

View Full Version : Control refuses to get focus


esox
02-04-2008, 07:09 AM
Hello all,
I have a few '<input type="text" />' controls on my ASP.NET 2.0 generated page.
Every text-box control has it's specific tab-index.
When I try to move focus to this specific text-box control on this page the focus is shifted to the window element instead of the control itself.
On every other text-box control on the page the focus is received fine.
To apply focus to this element I use the code: document.all.elemName.focus();

This is the control itself:

<input name = "ctl00$EditMasterContent$c_carats"
type = "text"
maxlength = "10"
id = "ctl00_EditMasterContent_c_carats"
tabindex = "6"
class = "textbox1"
onchange = "registerOnChangeAction(&quot;caratsChanged&quot;);"
onkeypress = "javascript:ChkNumberKeyPress(false);"
onfocus = "initFocusedElementsVar(this.id);"
style = "width: 100px;" />


Some other text-box control on the page:

<input name = "ctl00$EditMasterContent$c_stones"
type = "text"
maxlength = "5"
id = "ctl00_EditMasterContent_c_stones"
tabindex = "5"
class = "textbox1"
onchange = "registerOnChangeAction(&quot;stonesChanged&quot;);"
onkeypress = "javascript:ChkNumberKeyPress(false);"
onfocus = "initFocusedElementsVar(this.id);"
style = "width: 100px;" />

A1ien51
02-04-2008, 03:44 PM
well document.all is very bad to use. Foget that it exists.

With .NET the user controls are renamed so you can have more than one on the same page without name conflicts.

ideally you would be using

document.getElementById("elementId").focus();

What does your function initFocusedElementsVar(this.id) actually look like?

Eric