By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,661 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,661 IT Pros & Developers. It's quick & easy.

Experts Can you help me solve this dynamic textbox validation prob

P: n/a
Kum
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

Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
If I understand you correctly, you need a validator that confirms a real
date, integer, and email address have been entered. The ASP.NET validators
handle all of these cases without creating a custom control.
1. Use the CompareValidator to check the format of a date, integer, currency
and decimal. Set the Operator property to DataTypeCheck and Type property as
needed.
2. Use the RegularExpressionValidator for emails and other strongly
patterned strings. In fact, the ValidationExpression property has a cool
editor in the Properties Editor that lists common expressions including the
email address expression.

Now if you are trying to intelligently enable the validators based on the
DropDownList, you can simply change the Enabled property on the server-side.
It sounds like they are disabled initially (Enabled=false).

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Kum" <Ku*@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
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

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.