Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:31:11+00:00 2026-06-07T20:31:11+00:00

I have an asp:ListBox that contains multiple values. A user is required to always

  • 0

I have an asp:ListBox that contains multiple values. A user is required to always select one specific item in this box as well as optionally selecting others.

What is the best way to do this?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:31:13+00:00Added an answer on June 7, 2026 at 8:31 pm

    I think non of the ASP.Net validators fits your requirement out-of-the-box, what you need is to use the CustomValdiator and write server and client code to perform your validation

    Example:

    ASPX

    <script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
        function clientValidate(sender, args) {
            args.IsValid = false;
            $("#" + sender.controltovalidate + " option:selected").each(function (index, item) {
                if ($(this).text() == "QuestionText1") {
                    args.IsValid = true;
                    return;
                }
            });
        }
    </script>
    
    
        <asp:ListBox runat="server"
            SelectionMode="Multiple" ID="lb" AppendDataBoundItems="false"
            DataTextField="QuestionText" DataValueField="ID"
         >
            <asp:ListItem Text="text1" />
            <asp:ListItem Text="text2" />
        </asp:ListBox>
        <br />
        <br />
        <asp:CustomValidator ErrorMessage="errormessage" ControlToValidate="lb"
            ClientValidationFunction="clientValidate"
            OnServerValidate="cv_ServerValidate"
            runat="server" ID="cv" />
        <asp:Button Text="text" runat="server" />
    

    Code Behind

        protected void cv_ServerValidate(object sender, ServerValidateEventArgs e)
        {
            e.IsValid = false;
            foreach (ListItem item in this.lb.Items)
            {
                if (item.Selected)
                {
                    if (item.Text.ToLower().Trim() == "questiontext1")
                    {
                        e.IsValid = true;
                        break;
                    }
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET webform that has a listbox ( lbxRegions ) with multi-select
I have an ASP ListBox that has the SelectionMode set to "Multiple". Is there
On my Asp.NET website, I have a listbox that allows multiple selections. I'd like
i have a list: <asp:ListBox ID=lstProblems runat=server SelectionMode=Multiple></asp:ListBox> and i am populating it this
I have a multi-select <asp:listbox> and a button. I want to disable the button
I have a list box like this, <asp:ListBox ID=ListBox1 runat=server Height=175px Width=213px> <asp:ListItem Value=all>All</asp:ListItem>
I have a form that (amongst other things) contains 2 multi-select listboxes. Basically you
I have an ASP.NET listbox, lstActivities . To edit an item in the list,
I have an asp:ListBox control on my web page. I am trying to select
I have 2 asp:ListBox controls inside a table (side by side) that inside a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.