CustomValidator问题:
<%@ Page Language="C#"%>
<script runat=server>
void Button_Click( object s, EventArgs e ) {
if ( IsValid ) {
Response.Redirect( "ThankYou.aspx" );
}
}
void CustomValidator_ServerValidate( object s, ServerValidateEventArgs e ) {
string strValue;
strValue = e.Value.ToUpper();
if ( strValue.IndexOf( "ASP.NET UNLEASHED" ) > -1 ) {
e.IsValid = true;
} else {
e.IsValid = false;
}
}
</script>
<Script Language="JavaScript">
function CustomValidator_ClientValidate(s, e) {
var strValue;
strValue = e.Value.toUpperCase();
if (strValue.indexOf("ASP.NET UNLEASHED",0) > -1) {
e.IsValid = true;
} else {
e.IsValid = false;
}
}
</Script>
<html>
<head>
<title>CustomValidator.aspx</title>
</head>
<body>
<form Runat="Server">
Enter the name of your favorite book:
<br>
<asp:CustomValidator
ControlToValidate="txtFavBook"
ClientValidationFunction="CustomValidator_ClientValidate"
OnServerValidate="CustomValidator_ServerValidate"
Display="Dynamic"
Text="You must type ASP.NET Unleashed!"
Runat="Server" />
<br>
<asp:TextBox
ID="txtFavBook"
TextMode="Multiline"
Columns="50"
Rows="3"
Runat="Server" />
<p>
<asp:Button
Text="Submit!"
OnClick="Button_Click"
Runat="Server" />
</form>
</body>
</html>
运行显示错误:
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误信息: CS0103: 名称“True”在类或命名空间“ASP.CustomValidator_aspx”中不存在
源错误:
行 19: if(strValue.IndexOf("ASP.NET UNLEASHED")>-1)
行 20: {
行 21: e.IsValid=True;
行 22: }
行 23: else