单个验证器函数可在asp.net中以多种形式进行多重控制 [英] single validator function to multiple control in multiple form in asp.net

查看:66
本文介绍了单个验证器函数可在asp.net中以多种形式进行多重控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个函数/子例程,该函数/子例程检查必填字段,并允许控件在asp.net Web应用程序中仅输入数字或字母.

使用函数i我想一一传递.aspx页的所有控件,以使用于多个表单的Submit按钮起作用.

如果您对解决上述问题的asp.net/ajax/aspx控件的验证控件有任何建议,
请告诉我.

I want''s to make a function/subroutine which check for required field and allow control to enter only number or alphabet in asp.net web application.

Using function i Want to pass all controls of .aspx page one by one to function on submit button which is used for multiple form.

If u have any suggestion about validation controls of asp.net/ ajax/ aspx control which solve above problem ,
please tell me.

推荐答案

使用自定义验证器,并让它们全部调用通用JS文件中的函数.
Use custom validators and have them all call a function that''s in a common JS file.


CustomValidator控件为输入控件提供用户定义的验证功能.验证有两种类型
1.服务器端
2.客户端
这是您的问题的解决方案
在网页中插入自定义验证程序控件,然后分配以下属性
< asp:CustomValidator runat = server
controltovalidate ="txtName"
errormessage ="ID无效"
OnServerValidate ="CheckID"/>

在网页的代码后面编写以下代码以进行验证
公共无效CheckID(对象源,ServerValidateEventArgs args)
{
args.IsValid = true;
foreach(args.Value.ToString()中的char chr)
{
if(char.IsDigit(chr)==否&& char.IsLetter(chr)==否)
{
args.IsValid = false;
返回;
}
}
}

问候
库马兰
The CustomValidator control provides user-defined validation function for an input control. There are two types of validation
1. Server side
2. Client side
Here is the solution for your problem
Insert a custom validator control in the web page and assign the following properties
<asp:CustomValidator runat=server
controltovalidate="txtName"
errormessage="ID is not valid"
OnServerValidate="CheckID" />

Write the following code in code-behind of the web page for validation
public void CheckID(Object source, ServerValidateEventArgs args)
{
args.IsValid = true;
foreach (char chr in args.Value.ToString())
{
if (char.IsDigit(chr) == false && char.IsLetter(chr) == false)
{
args.IsValid = false;
return;
}
}
}

regards
Kumaran


这篇关于单个验证器函数可在asp.net中以多种形式进行多重控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆