How to do this validation in asp.net?

mylittlejava mylittlejava 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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.
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
mylittlejava
.NET社区 62,272 成员 668,968 内容