Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > unable to set focus to control after validation (must tab twice to exit control)

Reply
Thread Tools

unable to set focus to control after validation (must tab twice to exit control)

 
 
Mad Scientist Jr
Guest
Posts: n/a
 
      07-13-2004
i am trying to set focus to a specific control depending on the
outcome of a validator control and it is not working.

none of these methods are working to setfocus:

1. RegisterStartupScript("sf","<scriptlanguage='javas cript'>document.form.MyControlID.focus();</script>");

2. Andy Smith's FirstFocus control from
http://www.metabuilders.com/tools/FirstFocus.aspx

on my onchange event of field #1, based on the isvalid property of the
field #1 validators, i want to set focus either back to field #1 if it
is invalid, or to the next field #2 if it is valid. either way, it
always sets focus back to field #1 no matter what, so the user has to
press Tab twice to get to the next control, which is inconsistent with
all the other controls on the screen:

note the field names are generic Text1 and Text2 for simplicity

any help would be appreciated

Private Sub Text1_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Text1.TextChanged

'run validation event
RequiredFieldValidator_Text1.Validate()
RegularExpressionValidator_Text1.Validate()

If (RequiredFieldValidator_Text1.IsValid and
RegularExpressionValidator_Text1.IsValid) then
' RECALCULATE SOME FIELDS
Call ReCalculateFields()
End If

' SET FOCUS ON NEXT CONTROL IF VALID, ELSE STAY IN SAME
CONTROL

Dim FirstFocus1 As MetaBuilders.WebControls.FirstFocus
FirstFocus1 = New MetaBuilders.WebControls.FirstFocus
FirstFocus1.Enabled = True

If RequiredFieldValidator_Text1.IsValid And
RegularExpressionValidator_Text1.IsValid Then ' goto next control

'this didn't work:
'Page.RegisterClientScriptBlock("SetFocus", "<script>
language='javascript'>document.body.onload = function(){
document.form.Text2.focus();}</script>")

'this didn't work either
'RegisterStartupScript("SetFocus1",
"<scriptlanguage='javascript'>document.form.Text2. focus();</script>")

'this also doesn't work:
FirstFocus1.ControlToFocus = Text2.UniqueID

Else

'this didn't work:
'Page.RegisterClientScriptBlock("SetFocus", "<script>
language='javascript'>document.body.onload = function(){
document.form.Text1.focus();}</script>")

'this didn't work either:
'RegisterStartupScript("SetFocus1",
"<scriptlanguage='javascript'>document.form.Text1. focus();</script>")

'this also doesn't work:
FirstFocus1.ControlToFocus = Text1.UniqueID

End If
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
Set tab to skip fields -- or tab down sfp HTML 1 02-05-2007 09:13 PM
exit after process exit ajikoe@gmail.com Python 2 05-31-2005 08:11 PM
how do you set focus to next control on controls with autopostback so you don't have to hit tab twice? Mad Scientist Jr ASP .Net 2 06-29-2004 01:28 PM
Unable to set focus to textfield in a applet if browser is set to Sun JRE 1.4 Manav Java 0 10-15-2003 03:42 PM



Advertisments