Azaad Abbas

Azaad Abbas

  • NA
  • 221
  • 41.5k

Why Required Field not working for dropdownlist?

Mar 26 2015 2:39 AM
<%--for this working--%>
<asp:UpdatePanel ID="upddlPackPeriod" runat="server"><ContentTemplate>
<asp:dropdownlist ID="ddlPackPeriod" runat="server" AutoPostBack="True" onselectedindexchanged="ddlPackPeriod_SelectedIndexChanged" TabIndex="9">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="Monthly">Monthly</asp:ListItem>
<asp:ListItem Value="Quarterly">Quarterly</asp:ListItem>
<asp:ListItem Value="HalfYearly">HalfYearly</asp:ListItem>
<asp:ListItem Value="Yearly">Yearly</asp:ListItem>
</asp:dropdownlist>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlPackPeriod" />
</Triggers>
</asp:UpdatePanel>
<asp:RequiredFieldValidator ID="regPackPeriod" ControlToValidate="ddlPackPeriod" InitialValue="0" ErrorMessage="*Please Select Period" runat="server" ForeColor="Red"></asp:RequiredFieldValidator>
<%--for this not working--%>
<asp:UpdatePanel ID="upddlPayBy" runat="server"><ContentTemplate>
<asp:dropdownlist ID="ddlPayBy" runat="server"
onselectedindexchanged="ddlPayBy_SelectedIndexChanged" TabIndex="18" AutoPostBack="True">
<asp:ListItem Selected="True">SELECT</asp:ListItem>
<asp:ListItem Value="cash">Cash</asp:ListItem>
<asp:ListItem Value="cheque">Cheque</asp:ListItem>
</asp:dropdownlist>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlPayBy" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:RequiredFieldValidator ID="reqddlPayBy" runat="server" ControlToValidate="ddlPayBy" InitialValue="0" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>

Answers (4)