asp.net中的文本框验证 [英] textbox validation in asp.net

查看:86
本文介绍了asp.net中的文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用文本更改事件来验证文本框不应为空白?

how i can validate that textbox should not be blank using text changed event??

推荐答案

引用:
自验证ASP.NET文本框 [ http://msdn.microsoft.com/en-us/library/ms972961.aspx [ ^ ]
Refer:
Self Validating ASP.NET Text Box[^]
http://msdn.microsoft.com/en-us/library/ms972961.aspx[^]


您可以借助RequiredFieldValidater验证控件来检查空白文本框(文本框不应为空白).

You can take the help of RequiredFieldValidater validation control for checking blank textbox(textbox should not be blank).

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="should not be blank !!"></asp:RequiredFieldValidator>


具有事件,应将AutoPostBack设置为True然后使用此事件:
with events you should set AutoPostBack to True then use this event :
protected void btnSubmitForm_Click(object sender, EventArgs e)
{
   if(textbox1.Text=="")
  {
    //do anything you want
  }
}


然后检查它是否为空白...


您也可以使用它:


then check if it is blank ...


you can use this too :

<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" controltovalidate="txtName" xmlns:asp="#unknown">
ErrorMessage="Enter your name!" 
ForeColor="Red">
</asp:requiredfieldvalidator>


这篇关于asp.net中的文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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