focus on control after an error

  • Thread starter Thread starter saurabh
  • Start date Start date
S

saurabh

Hey,
I have a form in which there are say 10 fields. I am using validator
control for all the fields. suppose user forgets to fill field no. 5, 8
, 9 and 10.
So on clicking the save button,obviously an error willl be raised. Is
there anyway such that when the error is raised the focus goes to
first control that has false validation (e.g in our case that control
is 5) ? Right now after clicking the save button, none of the control
has the focus.
 
Set the SetFocusOnError portery of the validator control. if you have client
side validation enabled as soon as the user moves out of the textbox, if
there is an error, the focus will immedietly move back to the relevent text
box.
 
If using ASP.NET 2.0, use SetFocusOnError...

Set the SetFocusOnError portery of the validator control. if you have
client
side validation enabled as soon as the user moves out of the textbox, if
there is an error, the focus will immedietly move back to the relevent text
box.
 
I am using 1.1.4322 and couldnt find any property like that :( Tell me
is there any workaround ?
what if more than two controls have error. Which control will have the
focus?? in my case i want 5th control to get focus.(basically the
control which is above all other controls having error)
 
Sorry i forgot it's a .net 2.0 thing.

saurabh said:
I am using 1.1.4322 and couldnt find any property like that :( Tell me
is there any workaround ?
what if more than two controls have error. Which control will have the
focus?? in my case i want 5th control to get focus.(basically the
control which is above all other controls having error)
 
asp.net 1.1 does not provide this functionality..To do this, you have to
write your own javascript code.
 
If you are using ValidationSummary control to list the error
messages..I will give you a hint, how you can approach the problem..

If you open WebUIValidation.js file, you would see
"ValidationSummaryOnSubmit" function. This function determines if the
page is valid or not.. then if the page is not valid.. it will iterate
through all the invalid validators on the page and get the error
messages from them and list them in a bulleted format or other
according to the way you customize it.. So, you should be able to get
the ID's of all the invalid validator controls from this method.. so
see if you can solve your problem from there..
 
Back
Top