There are several way to do this. I'll assume, since you didn't post much information.
I assumed your application has dropdowns like below.
//ddl1
//ddl2
<asp:DropDownList ID="ddl3" runat="server">
<asp:ListItem Text="Select" Value=""></asp:ListItem>
<asp:ListItem Text="Option 1" Value="1"></asp:ListItem>
<asp:ListItem Text="Option 2" Value="2"></asp:ListItem>
<asp:ListItem Text="Option 3" Value="3"></asp:ListItem>
<asp:ListItem Text="Option 4" Value="4"></asp:ListItem>
</asp:DropDownList>
...
Then the client side validation will look something like below
<script type="text/javascript">
function Validate() {
var Xddl1 = document.getElementById("<%=ddl1.ClientID %>");
var Xddl2 = document.getElementById("<%=ddl2.ClientID %>");
var Xddl3 = document.getElementById("<%=ddl3.ClientID %>");
var Xddl4 = document.getElementById("<%=ddl4.ClientID %>");
if (Xddl1[Xddl1.selectedIndex].value == "" &&
Xddl2[Xddl2.selectedIndex].value == "" &&
Xddl3[Xddl3.selectedIndex].value == "" &&
Xddl4[Xddl4.selectedIndex].value == "") {
alert("Please select atleast one!");
return false;
}
return true;
}
</script>
On second though, let keep it simple. Above code should work. The code below is per control, you might need to look into
CustomValidator Control[
^] to ensure at least one value from the dropdown list is being selected.
My prefer alternative is to use the Validation control which will handle the client and server side validation. Here is an example.
//ddl1
...
<asp:DropDownList ID="ddl4" runat="server">
<asp:ListItem Text="Select" Value="0"></asp:ListItem>
<asp:ListItem Text="Option 1" Value="1"></asp:ListItem>
<asp:ListItem Text="Option 2" Value="2"></asp:ListItem>
<asp:ListItem Text="Option 3" Value="3"></asp:ListItem>
<asp:ListItem Text="Option 4" Value="4"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
Display="Dynamic" ControlToValidate="ddl4" InitialValue="0"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" />
The above markup should handle the client side validation. Then on the server side, the code should call the Page.IsValid method to make sure whatever posted to the server are valid.
if (Page.IsValid)
{
}