Thursday, March 23, 2017

How to use multiple validators for one control at same place?

Scenerio:
Let suppose I have a textbox for email and I want to validate that user must enter valid email address. In this statement there are two checks:
  1. User must enter email address – Required field
  2. Email address must valid email address
To do this two validator are required so it is required to use RequiredFieldValidator and RegularExpressionValidator both but the problem is that when we put these control adjacent to each other as below:
clip_image001
If we do this then email validation message shown far from the text box because RequiredFieldValidator still maintain their place.
clip_image002
Solution:
Set the Display property to Dynamic on RequiredFieldValidator and RegularExpressionValidator. After doing this it render correctly.

clip_image003




No comments :

Post a Comment