Wednesday, March 28, 2012

text box, command button and required field Validator

there is one text box, command button and one required
field validator control on a web form.
i want user to enter the data in text box i.e it is
mandatory field. so i had used required validator for
this purpose. all works perfectly it gave me the
message that please insert the data etc. but the
problem is that after that i want focus to be put back
on the control. [ please give me the solution keeping
in mind that there could be many such controls on the
form and i want to set focus on respective text box if
user doesn't enter the value for mandatory fiels ]If you want focus back on the textbox, you're in for a lot of work. Its not hard to put focus on the control using javascript, that's easy enough.

The problem stems from what you later ammend to your question (there could be many such controls). Ok... so if there's only one control, that control gets the focus. But if there are five, the fifth one will get focus (because each will apply focus, but the last one to attempt to do so will be the one that wins). And if the last control gets focus, what's the point really - you want it to be user friendly, and the user is going to want to start at the top, not at the bottom of the page.

So you now have a problem - how do you get focus on the first control on what could be a possible list of included controls. For that - you need a way to store the collection of the controls, and some code to determine which is the top-most (first rendered) control that flunked validation and requires focus.

You will need to tip-toe through the server-client architecture, using a combination of code-behind and javascript to do so.

If you wish to explore it further - you best describe more on what your control is (you mention a textbox, validator, and a button - button for each control or one button on the entire page?)

0 comments:

Post a Comment