Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide unnecessary space when validation error messages are not firing in ASP page

Tags:

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?

like image 698
devan Avatar asked May 12 '12 10:05

devan


People also ask

How remove validation message after field is valid in MVC?

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.

How do I turn off required field validator?

Well you can simple use the Enabled="false" property of RequiredFieldValidator .

Where do the asp net validation control validate data?

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.


1 Answers

You need to set

Display="Dynamic" 

property to your validator, this will cause desirable behaviour.

like image 157
Johnny_D Avatar answered Oct 01 '22 21:10

Johnny_D