Hi I am developing a web page which will give the details of customer. I have several validations for input fields and used DetailsView for displaying details of customer. If the user details does not exist in database Detailsview displays a message “No records found”. Now if I enters an invalid user name validations are displayed but page still have the “No records found” message in EmptyDataTemplate of DetailsView. How can I remove “No records found” message or disable details view ? So that page should only show error messages and textbox fields.
<asp:TextBox ID="TextBox_FirstName" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator_FirstName" runat="server"
ControlToValidate="TextBox_FirstName" ErrorMessage="Enter a valid SSN" ForeColor="Red"
SetFocusOnError="True">*</asp:RegularExpressionValidator>
<br />
<asp:TextBox ID="TextBox_LastName" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator_LastName" runat="server"
ControlToValidate="TextBox_LastName" ErrorMessage="Enter a valid date" ForeColor="Red">*</asp:RegularExpressionValidator>
<asp:Button ID="txtSubmit" Text="Validate" runat="server" />
<asp:CustomValidator ID="AtLeastOneTextBoxValidator" runat="server" ClientValidationFunction="Validate_Textbox"
ValidateEmptyText="true"> </asp:CustomValidator>
<asp:ValidationSummary ID="ValidationSummary" runat="server" />
<asp:DetailsView ID="Client_DetailsView" runat="server">
<EmptyDataTemplate>
<strong>No Record Found.</strong>
</EmptyDataTemplate>
</asp:DetailsView>
Change your code behind so that Client_DetailsView only gets data bound when they submit the form.
Also, set it’s visibility to hidden in the .aspx then only set it to visible when the form is submitted.