Hi,
I need help in asp.net dynamic textbox controls
validation.
I am creating textbox controls dynamically on a
asp.net webpage. Now after creating the textboxes on
the page I want to validate these text boxes when the
user submits or posts back to the server. My intention
was to create a textboxvalidator function which takes
the control name as argument and returns an true if
valid else the corresponding error message. The
situation is complex as the multiple textboxes
dynamically generated will have different data types.
Scenario:
1. User opens a webpage and selects a number in a
dropdownbox and submits
2. Depending on the number selected, correspondingly
dynamic textboxes are generated with id textbox1,
textbox2, etc and shows up on the webpage.
3. User then fills the textbox1,
textbox2,etc...textbox30...
4. Now I need to check the values entered in textbox1,
textbox2, etc..
5. The textbox1 should be valid date, textbox2 should
be valid number, textbox3 should be valid email and so
on..
My solution could have been that I generate
customvalidation controls for each and every textbox
dynamically created and assign the control to be
validated as the corresponding textbox id. However, I
am not sure if that is a good approach. Because if the
user selects 50 we need to created 50 customvalidation
controls.
Rather i feel it would be better to write a common
validateDatetextbox(textboxcontrolid),
validateNumbertextbox(textboxcontrolid), etc functions
and pass the textbox id to this function to check the
validity of that textbox.
I am not sure which is the best approach and how I
proceed. I greatly appreciate if some one could send
me a sample code of how to do this.
Thanks in advance
Mike