Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one textbox and one button on my aspx page.

code is:
XML
<div class="panel-body">
               <div class="form-group col-md-12">
                   <table>
                       <tr>
                           <td>
                               <label for="email" class="col-md-2 text-left">Please Enter Email ID:</label></td>
                           <asp:HiddenField ID="hdnCheckValidation" runat="server"/>
                           <td>
                               <asp:TextBox ID="txtEmailId" class="form-control" runat="server" Width="350px" onKeyPress="edValueKeyPress();"></asp:TextBox>
                               <asp:Button id="btnSave" runat="server" Text="Check Email Validity" class="form-control" ValidationGroup="ChangeStatus" OnClick="btnSendMail_Click" CausesValidation="true"/>
                               <asp:RequiredFieldValidator ID="rfvEmailAddress" runat="server" ControlToValidate="txtEmailId"
                                    ErrorMessage=" *" CssClass="bottom-left" ForeColor="Red" ValidationGroup="ChangeStatus" ></asp:RequiredFieldValidator>
                               <asp:RegularExpressionValidator ID="revEmailAddress" ControlToValidate="txtEmailId"
                                   runat="server" ErrorMessage=" Invalid Email Address" ValidationGroup="ChangeStatus"
                                   ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" CssClass="bottom-left" ForeColor="Red"></asp:RegularExpressionValidator>
                           </td>
                       </tr>
                   </table>
               </div>


Validators fires on button click(It's Working).
But it should not fire on clicking anywhere in the form.
Posted

How it possibly can be a problem? Then just remove all ASP.NET markup related to validation. Instead, add a handler to the Click event of a button you need and perform validation on click.

Also, remember that some validation can be done purely on the client side, in JavaScript, which also has regular expression. It will give you much better performance, but you should not use it if this is related to security. As this is just a validation of correct format of e-mail address (as far as I could see), JavaScript validation can be good for your.

—SA
 
Share this answer
 
v2
You could set the property CausesValidation to false on all of the other controls where you don't want them to trigger validation.
 
Share this answer
 
On your regular expression validator , add EnableClientScript="false" to disable the validations on the server side and it will validate on the server side.
 
Share this answer
 
Change the property CausesValidation of Button to True
 
Share this answer
 
v6

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