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.
解决方案 »
- Hashtable的问题
- 有谁做过“手机短信充值”功能?
- asp.net控件套用页面问题
- .net三层架构问题~~高手给解决一下
- ******************请教愚翁,WebDiyer,孟子E章,关于c#里调用c++写的dll的问题***************************
- 请大家给一些主页登陆注册系统的思路
- 提示错误在0行中无任何数据???在线等~~~~
- 不可访问“szyjr.internet.Button1_Click(object, System.EventArgs)”,因为它受保护级别限制
- 用户控件的使用问题
- (急需)在线编辑word的组件
- 怎样屏蔽"回车"自动触发Click事件? 急!急!急!
- 本人使用DataGrid中的ButtonColumn列,但怎么也取不到e.Item.Cells中的值,请高手指教
btLogin.Attributes.Add("onclick","return ValidUserName()");,同时你的ValidUserName函数需要修改一下return的值。这样按下按钮后,会先执行ValidUserName(),如果返回true接着执行后台代码验证rule 2