i want to validate many textboxes with same condition....Do i need to write code for each text boxes...plzz help
How to validate may text box with same condition
Collapse
X
-
Tags: None
-
No, you do not need to write code to validate each text box individually. There are several ways to validate text in a more generic way, but it depends on how you want to trigger your validation logic.
If you are using the text changed event, or some other text box event, to trigger your validation logic, then you can have all of your text boxes target the same event handler. Remember that any event handler has the sending object as one of the parameters for the function so you know which text box triggered the event. You would need to cast the "sender" parameter to a text box and then perform your validation on that object.
If you are using some sort of button click or other action, then you have to create a list of some kind that holds references to all of the text boxes that you wish to validate. Then it is just a matter of cycling through the list and performing the same validation for each text box.
If this isn't what you had in mind post back with an example of how you are validating one text box and that will give us more to work from.
Comment