为什么每次单击按钮时,该label
字段总是显示“GOOD”。
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
void Validate(Object obj, ServerValidateEventArgs args)
{
args.IsValid = false;
}
void click(Object obj, EventArgs args)
{
if (Page.IsValid)
{
label.Text = "GOOD";
}
else
{
label.Text = "FALSE";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label runat="server" Text="Please input a name" />
<asp:TextBox runat="server" ID="input"/>
<asp:CustomValidator runat="server" ID="validator" ControlToValidate="input" OnServerValidate="Validate"/>
<asp:Button runat="server" OnClick="click"/>
<asp:Label runat="server" ID="label"/>
</div>
</form>
</body>
</html>
但是当我在 中删除ControlToValidate="input"
时<asp:CustomValidator>
,一切正常。
为什么?