public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

Textbox with autopostback and regularexpression validator

Posted by Virendra Dugar on June 5, 2009

Quick summary of what’s changed in ASP.NET Core 1.0

Suppose you have a textbox on your aspx page that has a autopostback set to true and It makes a call to server side function on TextChanged Event. You have also placed a RegularExpression Validator which validates the textbox value against the validation expression.

For example: You want to allow only numeric characters in the text box and you have placed a regular expression validator to achieve this. And you also want to do some server side operation on text change.

 TextBox and RegularExpression Validator
When you run the application and if you type any alphabets in the textbox, the regular expression validates the input, it shows the error message but the weird thing is it also does the post back and call the server side text change event and error message is gone. This is what you don’t want. TextChange event must be called only when inputs are correct. Then how do you do this?

A very simple solution. Just set the CausesValidation="true" for the textbox and you are done.


Learn new ASP.NET Core 1.0 Framework


11 Responses to “Textbox with autopostback and regularexpression validator”

  1. Thanks! Just what I was looking for.

    I only wish I’d found this before spending half a day trying to re-trigger the validation from javascript…

  2. hackzai said

    Great tips and that pull me out from the hole. 🙂

  3. danar said

    thank u r great very good job and helpful thank u again

  4. cherly said

    thanks!! really help me a lots !!

  5. ksee00 said

    brilliant example..

  6. Sachin said

    What wrong you are telling, for float number it is not working

  7. Indrajeet said

    Thanks alot!

  8. Eman said

    And if i dont want to validate the rest of controls?

  9. karthik said

    but another textbox has making a validation in the same form

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: