How to do this validation in asp.net?
I am new on asp.net programming.
Here I got a problem about validator
I want to write a login.aspx page, for example, there is UserName box. I need to validate two things on UserName box,
1. It must be filled. If it is empty, I will show a red message right after this box, like "UserName is empty!"
2. It must be a valid user in our database. So on server side, we will check this UserName in our database. If it is not in our database, we will show something like "Invalid user name..."
I know it is very easy to do the 1st rule with the RequireFieldValidator. But in order to do the rule 2, I need to put a Lable at the same place where the validator is. Right? But the two won't stay at the same place. So I tried to use a CustomValidator, and write the ClientValidationFunction like this:
<script language="javascript">
function ValidUserName(oSrc, args) //For rule 1
{
if(args.Value.length > 0)
args.IsValid = true;
else
args.IsValid = false;
}
</script>
And also, I have a server validate function which will process the rule 2.
But the problem is the client validate function never get called. So , do you guys have a better solution for this? I really appreciate.
Here I got a problem about validator
I want to write a login.aspx page, for example, there is UserName box. I need to validate two things on UserName box,
1. It must be filled. If it is empty, I will show a red message right after this box, like "UserName is empty!"
2. It must be a valid user in our database. So on server side, we will check this UserName in our database. If it is not in our database, we will show something like "Invalid user name..."
I know it is very easy to do the 1st rule with the RequireFieldValidator. But in order to do the rule 2, I need to put a Lable at the same place where the validator is. Right? But the two won't stay at the same place. So I tried to use a CustomValidator, and write the ClientValidationFunction like this:
<script language="javascript">
function ValidUserName(oSrc, args) //For rule 1
{
if(args.Value.length > 0)
args.IsValid = true;
else
args.IsValid = false;
}
</script>
And also, I have a server validate function which will process the rule 2.
But the problem is the client validate function never get called. So , do you guys have a better solution for this? I really appreciate.
...全文
相关推荐
ASP.NET MVC5验证系列之Remote Validation
"ASP.NET MVC5中的远程验证(Remote Validation)功能详解"ASP.NET MVC5引入了一种称为Remote Validation的功能,它允许开发者实现客户端验证,尤
How to use SFTP
How to use SFTP (with client validation - public key authentication) The topic How to use SFTP (with
ASP.NET jQuery 实例18 通过使用jQuery validation插件校验DropDownList
总结一下,ASP.NET中使用jQuery validation插件校验DropDownList的步骤如下:1.
ASP.NET MVC5验证系列之Fluent Validation
"这篇教程介绍了ASP.NET MVC5中的一种验证方式——Fluent Validation,它是针对.NET框架的一个开源验证库,利用Fluent接口和lambda表达式实现更清晰的实体验证。与
ASP.NET jQuery 实例17 通过使用jQuery validation插件校验ListBox
"ASP.NET jQuery 实例17教程讲解如何在Web开发中利用jQuery validation插件来增强ListBox(下拉列表框)的用户输入验证。此实例主要关注一个名为`rangeleng


