Click here to Skip to main content
15,921,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using 2 dropdownList.Error should fire when dropdown is select empty

What I have tried:

<asp:DropDownList ID="ddl1" runat="server">
<asp:ListItem Value="0">Select
<asp:ListItem Value="1">one
<asp:ListItem Value="2">
<asp:ListItem Value="3">two
<asp:ListItem Value="4">three

Second List item is blank When i click on it error message should get fier.
Blank data should not get save
Posted
Updated 5-Aug-16 3:41am

try this

ASP.NET
<asp:Button runat="server" ID="btnSave" Text="Save" OnClientClick="return Validate();" OnClick="btnSave_Click" />



JavaScript
function Validate()
        {
            var ddl1 = document.getElementById('<%= ddl1.ClientID %>');
            var ddl2 = document.getElementById('<%= ddl2.ClientID %>');
            debugger;
            if (ddl1.options[ddl1.selectedIndex].text == '' || ddl1.options[ddl1.selectedIndex].text == '')
            {
                alert('Please enter the data');
                return false;
            }
            return true;
        }
 
Share this answer
 
Ill probably do something along these lines


One

two


jquery Onclick()

if($("#ddl1").val()==""){
//throw error
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900