文本框使用自定义验证器突出验证 [英] textbox focus out validation using custom validator

查看:53
本文介绍了文本框使用自定义验证器突出验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用验证控件来验证文本框.当我输入一些文本并且焦点不在时,它应该显示一条自定义验证器消息,说明输入的文本是否有效.我已在textchanged事件中编写了代码,并创建了一个带有控件的自定义验证器,以验证为文本框.我正在根据我在textchanged事件中的要求设置错误消息和消息的颜色.

I need to validate text box using validation controls. When i enter some text and the focus is out it should display a custom validator message stating whether the entered text is valid or not. i have written the code in textchanged event and i have created a custom validator with control to validate as textbox. i am setting the error message and color of the message as per my requirement in textchanged event.

推荐答案

您说您已经创建了一个自定义验证器来验证TextBox.那么为什么需要textchanged事件?

您可以使用JavaScript轻松实现这一目标.编写代码以检查TextBox onblur事件中的值.像这样的东西:
You said you have created a Custom Validator to validate the TextBox. Why do you need textchanged event then?

You can easily achieve this using JavaScript. Write code to check the values in onblur event of the TextBox. Something like this:
<asp:TextBox ID="TextBox1" runat="server" onblur="return validateData();"></asp:TextBox>





function validateData()
{
    //write validation code here.
}



希望这对您有帮助!



Hope this helps!


在文本框的离开"事件上编写验证器代码,如果验证失败,请继续关注该文本框(textbox1.focus();)
write your validator code on the Leave event of textbox,and if validation failed keep the focus on that textbox(textbox1.focus();)


这篇关于文本框使用自定义验证器突出验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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