Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys

I used this code:

XML
<asp:TextBox ID="_textBoxCustomerNr" runat="server" Width="150"></asp:TextBox>
<br />
<asp:RegularExpressionValidator ID="_regularExpressionValidatorCustomerNr" runat="server" Display="Dynamic" ControlToValidate="_textBoxCustomerNr" ValidationExpression="^[\s\S]{3,50}$" EnableClientScript="false"
ErrorMessage="Customer Nr. too short!">
</asp:RegularExpressionValidator>


Now what I want:

whenever I enter something int the textBox _textBoxCustomerNr, the RegularExpressionValidator should be validated and the error message should be displayed.

this works for the first textbox but not for the others, why? Did I forget something? I turned EnableClientScript to "true" for every textbox, but that doesn't help anything. Now it's turned into "false" - only for the first one.


I would be very happy for every help.

Thanks
valentigra
Posted
Comments
Er Daljeet Singh 22-Nov-13 4:19am    
post the whole code here.
so we can find where is the problem.
v_tigra 22-Nov-13 4:28am    
that's the code, I already posted it. Every other textbox has the same code (only ID changes)s
Er Daljeet Singh 22-Nov-13 4:55am    
but the code you have posted work fine if you set EnableClientScript=true.
this property simple check whether you want to check the validation at server of client side.
if this property is true then its means we want to check the validation at client side.

Hi valentigra,

If you want other text box to validate the same condition then you should use another asp:RegularExpressionValidator control with ControlToValidate ="_Text2" attribute.
Since you have set _regularExpressionValidatorCustomerNr with attribute ControlToValidate to only one textbox that is _textBoxCustomerNr, you cant expect other textbox to follow the same validation.
For every text box you should have individual Regularexpression validation control.

Updated solution:

EnableClientScript="True" also did not work for you?

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v4
Comments
v_tigra 22-Nov-13 7:12am    
yes that's right, but I also have individual regularexpressions for every textbox.. I still don't understand why it only works for the first one.
♥…ЯҠ…♥ 22-Nov-13 7:19am    
If you want 3 text box to validate, then you need to add three regularexpressionvalidator with controltovalidate attribute assign to each and every textbox resp., then only it will satisfy what you are expecting in this case.
v_tigra 22-Nov-13 7:47am    
Please read my comment at solution 3 - maybe you can help me better after reading it
♥…ЯҠ…♥ 22-Nov-13 8:01am    
Now i got, but totally weird situation... i'll google it for you
v_tigra 22-Nov-13 8:07am    
thank you a lot, I already googled for it and didn't find what I was searching for. I hope you can help me.
Hi valentigra,

Solution 1 is best , you just need to set validation group property of all text boxes same also for button on which you have to perform all this validations.
You must need separate Regular Expression Validation For each textbox if you want to do validation using RegularExpressionValidator.
Or you can write validation function programatically and call that function for each textbox entry.?



reply me If it works or not ?
 
Share this answer
 
Comments
v_tigra 22-Nov-13 7:18am    
I don't want to execute this validations by clicking the button, I really would like to get error-messages by entering something wrong in the individual textboxes.

Example:

I have TextBox Name and TextBox E-Mail, both TextBoxes got individual RegularExpressionValidators (ID="regexValidatorName" and ID="regexValidatorEmail"). The character length of TextBox Name must be between 3 and 50. So, if I write "S", the errorMessage must be shown directly next to the TextBox containing this sentence "Name too short!". Same by the TextBox Email.
The validation should be done while writing, not if I click a button, do you understand now what I want to do with those regularexpressionvalidators?
[no name] 22-Nov-13 23:57pm    
for name validation what expression you write ?
Can you tell me your test cases for above questions .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900