CustomValidator
来源:互联网 发布:王俊凯人品知乎 编辑:程序博客网 时间:2024/05/16 11:39
CustomValidator控件具体实现客户端验证,服务器验证和混合式验证三种模式
1. 客户端验证
aspx
<head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script> function clientValidate(source, args) { if ((args.Value % 2) == 0) args.IsValid = true; else args.IsValid = false; } </script></head><body> <form id="form1" runat="server"> <div> 数值: <asp:TextBox ID="txtInput" runat="server"></asp:TextBox> <asp:CustomValidator ID="cvInput" runat="server" ErrorMessage="CustomValidator" ControlToValidate="txtInput" ClientValidationFunction="clientValidate">不是一个偶数!</asp:CustomValidator> <br /> <asp:Button ID="btnSubmit" runat="server" Text="确定" OnClick="btnSubmit_Click" OnClientClick="btnSubmit_Click" /> <asp:Label ID="lblMsg" runat="server" ></asp:Label> </div> </form></body>
.cs
protected void btnSubmit_Click(object sender, EventArgs e) { if(Page.IsValid) { lblMsg.Text = "验证通过"; } }
服务器验证
aspx
<div> 数值: <asp:TextBox ID="txtInput" runat="server" OnTextChanged="txtInput_TextChanged"></asp:TextBox> <asp:CustomValidator ID="cvInput" runat="server" ErrorMessage="CustomValidator" ControlToValidate="txtInput" OnServerValidate="cvInput_ServerValidate">不是一个偶数!</asp:CustomValidator> <br /> <asp:Button ID="btnSubmit" runat="server" Text="确定" OnClick="btnSubmit_Click" OnClientClick="btnSubmit_Click" /> <asp:Label ID="lblMsg" runat="server" ></asp:Label> </div>
.cs
protected void btnSubmit_Click(object sender, EventArgs e) { if(Page.IsValid) { lblMsg.Text = "验证通过"; } } protected void cvInput_ServerValidate(object source, ServerValidateEventArgs args) { int value = int.Parse(args.Value); if((value%2)==0) { args.IsValid = true; } else { args.IsValid = false; } }
阅读全文
0 0
- CustomValidator
- CustomValidator
- CustomValidator 控件
- CustomValidator控件
- customvalidator的使用
- 自定义判断控件customvalidator
- CustomValidator控件的使用
- CustomValidator控件用法
- CustomValidator客户端验证DropDownList
- CustomValidator控件的使用
- CustomValidator添加客户端函数
- CustomValidator怎麼不好使了?
- customvalidator控件的使用
- CustomValidator自定义验证控件
- CustomValidator控件用法
- CustomValidator的使用方法
- Validating Checkboxlist using CustomValidator
- CustomValidator,客户端,服务器端验证
- CodeForces 864F Cities Excursions
- c++类的嵌套定义
- java stringbuffer stringbuilder
- ZBUS = MQ + RPC
- SpringMVC_@RequestBody
- CustomValidator
- Codeforces Round #436 (Div. 2)E.Fire
- 动态规划算法求解0-1背包问题
- android中判断包含某class,so文件
- Chrlea基本功能点总结
- 位操作
- javascript的格式匹配认证
- Photon_PhotonServer的启动及项目的启动_010
- git 基础以及常见错误