ASP.NET 中的控件
<asp:TextBox ID="txtEnd" runat="server" placeholder="12:59"></asp:TextBox>
<asp:RadioButtonList ID="rblTime2" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem>AM</asp:ListItem>
<asp:ListItem>PM</asp:ListItem>
</asp:RadioButtonList>
自定义验证器
<asp:CustomValidator ID="ValidateStartTime" ControlToValidate="txtEnd" OnServerValidate="ValidateStartTimeFun" runat="server" ErrorMessage="*required"></asp:CustomValidator>
代码隐藏
protected void ValidateStartTimeFun(object source, ServerValidateEventArgs args)
{
try
{ if (txtStart.Text != "" && rblTime.SelectedValue != null )
{ args.IsValid = true; }}
catch (Exception ex)
{ args.IsValid = false; }
}
如果我将整个 CodeBehind 更改为此,它甚至不会给我一个 *required;
protected void ValidateStartTimeFun(object source, ServerValidateEventArgs args)
{
args.isValid = false;
}