I want to validate some text boxes in my ASP.NET page using ASP required field validation. And I want to display that error message in top of the page.
<table> <tr><td colspan='2'><b> User Input</b><br/></td></tr> <tr><td colspan='2'> <%--input validations--%> <asp:RegularExpressionValidator ID="regexpName1" runat="server" ErrorMessage="This expression does not validate." ControlToValidate="TextBox_adTitle" ValidationExpression="^[a-zA-Z'.\s]{1,40}$" /> <br /> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox_1" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator> <br /> </td> </tr> <tr><td> <asp:Label ID="Label_name" runat="server" Text="Seller Name * "></asp:Label> </td> <td> <asp:TextBox ID="TextBox_1" runat="server" ReadOnly="True" ></asp:TextBox> </td> </tr> ...
This is working fine. However, the first table row is keeping its space even error messages are not displaying on it. This will cause the UI to look bad on the page since unnecessary space is there when the page loads.
How can I hide the space of the first row (validation's error messages row) while the page is loading and when there is no validation error?
So, to clear the validation errors, you can do something like this to a form : var fieldContexts = form. __MVC_FormValidation. fields; for(i = 0; i < fieldContexts.
Well you can simple use the Enabled="false" property of RequiredFieldValidator .
Where do the ASP.NET validation controls validate data, on the Client or on the Web Server? ASP.NET validation controls validate data on the client as well as web server. If we need to validate data on client side itself, we have to set a property to controls to execute at the client side.
You need to set
Display="Dynamic"
property to your validator, this will cause desirable behaviour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With