.net(C#)自定义验证控件问题!
这段代码的客户端验证程序怎么没有执行?<%@PageLanguage="C#"%><ScriptLanguage="C#"Runat="Server">publicvoi...
这段代码的客户端验证程序怎么没有执行?
<%@ Page Language="C#"%>
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
show.Text = "";
}
public void Button_Click(Object sender,EventArgs e)
{
if(Page.IsValid)
{
show.Text = "验证成功";
}
else
{
show.Text = "验证失败";
}
}
void ServerValidate(Object source , ServerValidateEventArgs value)
{
value.IsValid = false;
string[] members = {"飞刀","大风","孙雯","布丁","Zsir"};
bool just = false;
for(int i=0;i<members.Length;i++)
{
if(value.Value==members[i])
{
value.IsValid = true;
break;
}
}
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
<table>
<tr><td colspan=2 align="center"><b>CustomValidator控件</b></td></tr>
<tr>
<td>姓名:</td>
<td>
<asp:TextBox id="Text1" runat="server"/>
<asp:CustomValidator id="CustomValidator1" runat="server"
ControlToValidate="Text1"
ClientValidationFunction="ClientValidate"
OnServerValidate="ServerValidate"
Display="Static"
Font-Name="verdana" Font-Size="10pt"
>
你不是本工作室成员
</asp:CustomValidator>
</td>
</tr>
<tr><td><asp:Button Text="验证" runat="server" OnClick="Button_Click" /></td><td></td></tr>
</table>
</form>
<hr>
<asp:Label id="show" runat="server" />
<script Language="JavaScript">
<!--
function ClientValidate(source, value)
{
members = new Array();
members[0]="飞刀";
members[1]="大风";
members[2]="亚豪";
members[3]="Zsir";
members[4]="布丁";
members[5]="ZaZa";
just = false;
for(i=0;i<members.length;i++)
{
if(value==members[i])
{
just = true;
break;
}
}
return just;
}
-->
</script>
</body>
</html> 展开
<%@ Page Language="C#"%>
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
show.Text = "";
}
public void Button_Click(Object sender,EventArgs e)
{
if(Page.IsValid)
{
show.Text = "验证成功";
}
else
{
show.Text = "验证失败";
}
}
void ServerValidate(Object source , ServerValidateEventArgs value)
{
value.IsValid = false;
string[] members = {"飞刀","大风","孙雯","布丁","Zsir"};
bool just = false;
for(int i=0;i<members.Length;i++)
{
if(value.Value==members[i])
{
value.IsValid = true;
break;
}
}
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
<table>
<tr><td colspan=2 align="center"><b>CustomValidator控件</b></td></tr>
<tr>
<td>姓名:</td>
<td>
<asp:TextBox id="Text1" runat="server"/>
<asp:CustomValidator id="CustomValidator1" runat="server"
ControlToValidate="Text1"
ClientValidationFunction="ClientValidate"
OnServerValidate="ServerValidate"
Display="Static"
Font-Name="verdana" Font-Size="10pt"
>
你不是本工作室成员
</asp:CustomValidator>
</td>
</tr>
<tr><td><asp:Button Text="验证" runat="server" OnClick="Button_Click" /></td><td></td></tr>
</table>
</form>
<hr>
<asp:Label id="show" runat="server" />
<script Language="JavaScript">
<!--
function ClientValidate(source, value)
{
members = new Array();
members[0]="飞刀";
members[1]="大风";
members[2]="亚豪";
members[3]="Zsir";
members[4]="布丁";
members[5]="ZaZa";
just = false;
for(i=0;i<members.length;i++)
{
if(value==members[i])
{
just = true;
break;
}
}
return just;
}
-->
</script>
</body>
</html> 展开
展开全部
前台验证函数错误,return干吗~?不需要~~:
<script Language="JavaScript">
<!--
function ClientValidate(source, value)
{
members = new Array();
members[0]="飞刀";
members[1]="大风";
members[2]="亚豪";
members[3]="Zsir";
members[4]="布丁";
members[5]="ZaZa";
for(i=0;i<members.length;i++)
{
//text1是文本框的id
if(document.getElementById("text1").value==members[i])
{
value.IsValid = true;
return;
}
}
value.IsValid = false;
}
-->
</script>
<script Language="JavaScript">
<!--
function ClientValidate(source, value)
{
members = new Array();
members[0]="飞刀";
members[1]="大风";
members[2]="亚豪";
members[3]="Zsir";
members[4]="布丁";
members[5]="ZaZa";
for(i=0;i<members.length;i++)
{
//text1是文本框的id
if(document.getElementById("text1").value==members[i])
{
value.IsValid = true;
return;
}
}
value.IsValid = false;
}
-->
</script>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询