Reputation: 185
I have a control on an ASP.NET page with a required field validator. Only problem is that when I go to change pages via my page buttons it doesn't cause validation. Here is the code, can anyone see what's wrong?
<asp:Label ID="lblD_Year" runat="server" BorderStyle="None"
Text="Fiscal Year" CssClass="h2"></asp:Label>
<asp:DropDownList ID="ddlD_Year" runat="server" Width="100px" TabIndex="8"
AutoPostBack="True" CssClass="box" CausesValidation="True">
<asp:ListItem Value="0" Selected="True">Select Year</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvD_Year" runat="server"
ControlToValidate="ddlD_Year" Display="Dynamic" ErrorMessage="*"
Font-Bold="True" ForeColor="Red" InitialValue="Select Year"
SetFocusOnError="True"></asp:RequiredFieldValidator>
Upvotes: 1
Views: 3308
Reputation: 35572
set initial value as InitialValue="-1"
for validator or any value which you consider to be empty, if selected
Upvotes: 1
Reputation: 16134
Set InitialValue="0"
<asp:RequiredFieldValidator ID="rfvD_Year" runat="server"
ControlToValidate="ddlD_Year" Display="Dynamic" ErrorMessage="*"
Font-Bold="True" ForeColor="Red" InitialValue="0"
SetFocusOnError="True"></asp:RequiredFieldValidator>
Upvotes: 0