CustomValidator问题:

hiweiyi2000 2004-10-08 10:32:48
<%@ 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

...全文
377 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dulkernetbug 2004-10-11
  • 打赏
  • 举报
回复
应该是对的
saucer 2004-10-11
  • 打赏
  • 举报
回复
what .net version are you using? I tested on windows 2003 server, .net 1.1, it works fine

but if you don't enter anything, the validation also passes, if that is not what you want, you should also add a RequiredFieldValidator
hiweiyi2000 2004-10-11
  • 打赏
  • 举报
回复
顶一下,没有解决问题
hiweiyi2000 2004-10-08
  • 打赏
  • 举报
回复
我试了一下,不关true->True
minrange 2004-10-08
  • 打赏
  • 举报
回复
CustomValidator会自动形成javascipt脚本,以此来监控页面的提交,不需要自己写后台代码的
CSTerry 2004-10-08
  • 打赏
  • 举报
回复
True->true
happyjun2000 2004-10-08
  • 打赏
  • 举报
回复
up

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧