Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Drop in a custom validator, Add your desired error message to it, double click on the custom validator to get to the code behind for the event handler, and then you would implement server side like this:</p> <pre><code>protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) { args.IsValid = ListBox1.Items.Count &gt; 0; } </code></pre> <p>Also you can implement client side javascript as well. </p> <p>I just threw this up on a page and tested it quickly, so you might need to tweak it a bit: (The button1 only adds an item to the List Box)</p> <pre><code>&lt;script language="JavaScript"&gt; &lt;!-- function ListBoxValid(sender, args) { args.IsValid = sender.options.length &gt; 0; } // --&gt; &lt;/script&gt; &lt;asp:ListBox ID="ListBox1" runat="server"&gt;&lt;/asp:ListBox&gt; &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" ValidationGroup="NOVALID" /&gt; &lt;asp:Button ID="Button2" runat="server" Text="ButtonsUBMIT" /&gt; &lt;asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" onservervalidate="CustomValidator1_ServerValidate" ClientValidationFunction="ListBoxValid"&gt;&lt;/asp:CustomValidator&gt; </code></pre> <p>If you add a validation summary to the page, you error text should show up in that summary if there is no items in the ListBox, or other collection-able control, what ever you want to use, as long as the ValidationGroup is the same.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload