ASP.NET中javascript验证函数调用问题

shw586 2006-04-10 02:20:25
正在学习《ASP.NET技术内幕》第三章,我在做例题3-19时碰见难关,面思不得其解,请高手指点。(我用C#)改写了源程序,但其它都没有改动。
这个页面在运行时,客户检验函数老是出现错误,javascript不熟,只是照抄VB的格式,中间估计有问题,但我不知道怎么改,还望各路高手指点。
整个页面源代码如下:
<script runat=server language =c#>

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>

<html>
<head>

<script language="javascript">
function CustomValidator_ClientValidate(s,e)
{
var strValue;
strValue = e.value;
if (strValue.indexOf( "ASP.NET UNLEASHED" ) > -1 )
e.IsValid = true;
else
e.IsValid = false;

}

</script>

<title>CustomValidator.aspx</title>
</head>
<body>

<form id="form1" runat=server>

Enter the name of your favorite book:
<br>
<asp:CustomValidator
id="customValid"
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>


...全文
142 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
GaoXX 2006-04-15
  • 打赏
  • 举报
回复
顶一下
shw586 2006-04-10
  • 打赏
  • 举报
回复
两位正解。
哪位能解释一下CustomValidator_ClientValidate(s,e)中的s,e各是什么类型的参数吗?它们又各代表什么意义?我在调用这个函数的时候并没有传递这两个参数啊?是不是每个事件处理函数都有这两个参数啊?
clare2003 2006-04-10
  • 打赏
  • 举报
回复
ClientValidationFunction="CustomValidator_ClientValidate"//去掉"()"
strValue = e.value;
==>strValue = e.Value;
clare2003 2006-04-10
  • 打赏
  • 举报
回复
<script runat=server language =c#>

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>

<html>
<head>

<script language="javascript">
function CustomValidator_ClientValidate(s,e)
{
var strValue;
strValue = e.Value;

if (strValue.indexOf( "ASP.NET UNLEASHED" ) > -1 )
e.IsValid = true;
else
e.IsValid = false;


}

</script>

<title>CustomValidator.aspx</title>
</head>
<body>

<form id="form1" runat=server>

Enter the name of your favorite book:
<br>
<asp:CustomValidator
id="customValid"
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 ID="Button1"/>

</form>
</body>
</html>

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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