如何在ASP.NET中的文本框上应用非空验证 [英] How can I apply not empty validation on text boxes in ASP.NET

查看:125
本文介绍了如何在ASP.NET中的文本框上应用非空验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

i是jquery的新手,我想实现一个全局jquery或javascript函数来检查文本框是否为空......



我尝试了什么:



我的aspx代码是

我怎么能使用jquery或javascript验证此文本框

 <   asp:TextBox     ID   =   txt_Cat_Name    onKeyUp  < span class =code-keyword> =  CheckTextLength(this,15)    onChange   =  CheckTextLength(this,15)    onkeypress   =  return isAlfa(event)    runat   =  server    CssClass   = 文字 >  <  <跨度类= 代码leadattribute> / ASP:文本框 <跨度类= 代码关键字>>  

解决方案

通过编写脚本来处理事件,一个例子是:

< script> 
函数CheckTextLength(element,minLength){

if(element.value.length< minLength){
alert(Too short!);
返回false;
}
}
< / script>



和你的asp.net控件:

< pre lang =ASP.NET> < asp:TextBox ID = txt_Cat_Name onChange = CheckTextLength(this,15) runat = server CssClass = 正文 > < / asp: Ť extBox >


Hi everyone
i am new to jquery and i want to implement a global jquery or javascript function that check whether the text box is empty or not...

What I have tried:

My aspx code is
How can i use jquery or javascript to validate this textbox

<asp:TextBox ID="txt_Cat_Name" onKeyUp="CheckTextLength(this,15)" onChange="CheckTextLength(this,15)" onkeypress="return isAlfa(event)" runat="server" CssClass="Text"></asp:TextBox>

解决方案

By writing the script to handle the event, one example will be:

<script>
function CheckTextLength(element, minLength){

	if(element.value.length < minLength){
    	alert("Too short!");
        return false;
    }
}
</script>


and your asp.net control:

<asp:TextBox ID="txt_Cat_Name" onChange="CheckTextLength(this,15)"  runat="server" CssClass="Text"></asp:TextBox>


这篇关于如何在ASP.NET中的文本框上应用非空验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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