1

My page contains more than one dropdown list,in which some is mandatory fields,hence given required field validator.What i need is to include validation summarry,only if the datatable bound to DDL is empty,ie,only if the DDL contains no data to chose from.Ho to achieve this?

Sruthi Suresh
  • 697
  • 4
  • 22
  • What you are going to shown in `Validaton summary`? Explain little bit more – Sankar Feb 27 '16 at 05:36
  • i need the validation summary to be visible only if the count of items in drop down list is empty, and show an appropriate error message.and at the same time i need the require validator to be shown when items are there but not selected any..(as i didnt got the answer,i changed the ideaof using validation summary,and tried something else.is there a solution to this ) – Sruthi Suresh Feb 27 '16 at 08:12
  • Yes. you can achieve this by adding custom validator dynamically from code-behind. – Sankar Feb 27 '16 at 08:18
  • I have'nt used custom validator yet .I have done my work but I will learn and try your suggestion thank you :).... – Sruthi Suresh Feb 27 '16 at 08:32

1 Answers1

1

This is for your Knowledge:

<asp:panel ID="ErrorsPanel" runat="server" CssClass="ErrorSummary">
    <asp:CustomValidator id="CustomValidator1" runat="server" 
        Display="None" EnableClientScript="False"></asp:CustomValidator>
    <asp:ValidationSummary id="ErrorSummary" runat="server" 
        HeaderText="Errors occurred:"></asp:ValidationSummary>
</asp:panel>

Whenever you find the ddl is empty, you should execute this below code :

CustomValidator1.IsValid = False
CustomValidator1.ErrorMessage = "The DDL is Empty"

you can also use the Required field validator for the specific control.

Hope this helps...

Sankar
  • 6,908
  • 2
  • 30
  • 53