六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 29|回复: 0

3.8使用CustomValidator控件

[复制链接]

升级  57%

115

主题

115

主题

115

主题

举人

Rank: 3Rank: 3

积分
371
 楼主| 发表于 2013-1-26 14:30:18 | 显示全部楼层 |阅读模式
使用CustomValidator控件

CustomValidator三处重要属性:
ControlToValidator
Text
ClientValidationFunction  客户端验证的客户端函数名

支持事件 
ServerValidate -CustomValidator执行验证时引发

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    protected void valComments_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (args.Value.Length > 10)
            args.IsValid = false;
        else args.IsValid = true;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Show CustomValidator</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblComents" Text="Comments:" AssociatedControlID="txtComments" runat="server" />
        <br />
        <asp:TextBox ID="txtComments" TextMode="MultiLine" Columns="30" Rows="5" runat="server" />
        <asp:CustomValidator ID="valComments" ControlToValidate="txtComments" Text="(Comments must be less than 10 characters)"
            runat="server" OnServerValidate="valComments_ServerValidate" />
        <br />
        <br />
        <asp:Button ID="btnSubmit" Text="Submit" runat="server" />
    </div>
    </form>
</body>
</html>

----------------------------------------
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表