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 6820179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:23:40+00:00 2026-05-26T21:23:40+00:00

I have a dropdownlist and it is very simple. You click the button to

  • 0

I have a dropdownlist and it is very simple. You click the button to go further you have error if you don’t select nothing from DDL. But how i do to not appear the error when the user choose something from the DDL?

Here is the markup:

<asp:DropDownList ID="DropDownList1" runat="server" CssClass="jump">
     <asp:ListItem Text="" Value="0"></asp:ListItem>  
     <asp:ListItem Text="Coupé" Value="Coupé" />
     <asp:ListItem Text="Cabriolet" Value="Cabriolet" />
     <asp:ListItem Text="Pickup" Value="Pickup" />   
     <asp:ListItem Text="Kombi" Value="Kombi" />   
     <asp:ListItem Text="Kombi-Coupé" Value="Kombi-Coupé" />  
     <asp:ListItem Text="Minibuss" Value="Minibuss" />
     <asp:ListItem Text="Sedan" Value="Sedan" />    
     <asp:ListItem Text="Skåpbil" Value="Skåpbil" />
     <asp:ListItem Text="SUV" Value="SUV" />                      
     <asp:ListItem Text="Övrig" Value="Övrig" /> 
</asp:DropDownList>
<p id="err" runat="server"></p>  

and code-behind:

if (DropDownList1.SelectedIndex == 0)
{
    err.InnerHtml = "<span style='font: normal bold 11px/100% Arial, Verdana, Sans-Serif; color: Red'>Du måste välja Fordonstyp!</span>";
    return;
}

Thank you so much 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-05-26T21:23:40+00:00Added an answer on May 26, 2026 at 9:23 pm

    As simple as this:

    err.InnerHtml = "";
    if (DropDownList1.SelectedIndex == 0)
        {
            err.InnerHtml = "<span style='font: normal bold 11px/100% Arial, Verdana, Sans-Serif; color: Red'>Du måste välja Fordonstyp!</span>";
            return;
        }
    

    This will hide the error by default, then show it only if needed.

    Edit: to support more than one drop down wrap it nicely with a function first:

    private bool HandleDropDownError(DropDownList oDDL, HtmlGenericControl oErrorControl, string strErrorText)
    {
        oErrorControl.InnerHtml = "";
        if (oDDL.SelectedIndex == 0)
        {
            oErrorControl.InnerHtml = "<span style='font: normal bold 11px/100% Arial, Verdana, Sans-Serif; color: Red'>" + strErrorText + "</span>";
            return false;
        }
        return true;
    }
    

    Now just use the same error label to show error for any drop down, and have such code in the Page_Load:

    if (!HandleDropDownError(DropDownList1, err, "Du måste välja Fordonstyp!"))
        return;
    if (!HandleDropDownError(DropDownList2, err, "Du måste välja matta!"))
        return;
    if (!HandleDropDownError(DropDownList3, err, "Du måste välja byggnad!"))
        return;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic syntax question on Populating a dropdownlist box from dataset.
I have the following very simple form: <asp:UpdatePanel ID=ClaimRewardsForm runat=server> <ContentTemplate> <span class=largeBold>Select jacket
Let's assume I have a very simple form, with a submit button and a
I have DropDownList with CascadingDropDown extender. If I want to retrieve data from the
I have a dropdownlist and a textbox with a button on a form. When
I have a dropdownlist inside a gridview, that is loaded from a datasource when
I have a dropdownlist that has 4 columns but only 3 are 'visible' the
i have a dropdownlist that populates from the sql server database. populating the list
I have some DropDownList controls where the list is very large, so I would
I have a very long list of items for a dropdownlist. As the list

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.