M
Mad Scientist Jr
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='javascript'>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
outcome of a validator control and it is not working.
none of these methods are working to setfocus:
1. RegisterStartupScript("sf","<scriptlanguage='javascript'>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