1

我在带有必填字段验证器的 ASP.NET 页面上有一个控件。唯一的问题是,当我通过页面按钮更改页面时,它不会导致验证。代码如下,谁能看看有什么问题?

<asp:Label ID="lblD_Year" runat="server" BorderStyle="None" 
                       Text="Fiscal Year" CssClass="h2"></asp:Label>&nbsp;&nbsp;&nbsp;
                <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>
4

2 回答 2

1

设置验证器的初始值InitialValue="-1"或您认为为空的任何值(如果选择)

于 2012-06-04T18:49:59.057 回答
0

设置初始值=“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>
于 2012-06-04T18:40:25.837 回答