ASP.NET中javascript验证函数调用问题
正在学习《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>