空字段不应存储到数据库中 [英] Empty fields should not be stored into a database

查看:105
本文介绍了空字段不应存储到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将必需的字段验证器分配给文本框.如果该字段为空,我应该收到一条错误消息.当我单击提交"按钮,并且我在同一页面的其他文本框中输入的值不应存储在数据库中时,将出现此错误消息.
简而言之,空值不应存储到数据库中.
有人可以帮我吗?

I have assigned a required field validator to a textbox. I should get an error message if that field is empty. This error message should come when I click the submit button and the values that I have entered in the other textboxes on the same page should not be stored in the database.
In short the empty values should not be stored into the database.
Can anyone help me out?

推荐答案

尝试以下示例,看看我如何使用RequiredFieldValidator 来确保用户输入Name 字段.我相信,您可以实现自己的:)

Try this example and see how I used the RequiredFieldValidator to make sure that user enters the Name field. I believe, you can implement your own :)

<div>
       <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
       <asp:TextBox ID="TxtName" runat="server"></asp:TextBox><asp:RequiredFieldValidator

           ID="RequiredFieldValidator1" ControlToValidate="TxtName" runat="server" ErrorMessage="Name is required."></asp:RequiredFieldValidator>
       <br />
       <asp:Label ID="Label2" runat="server" Text="Address"></asp:Label>
       <asp:TextBox ID="TxtAddress" runat="server"></asp:TextBox>
       <asp:Button ID="Button1" runat="server" Text="Submit" />
   </div>


验证程序会执行此操作,它将停止页面回发.
A validator does that, it stops the page posting back.


这篇关于空字段不应存储到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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