空字段不应存储到数据库中

编程入门 行业动态 更新时间:2024-10-25 00:28:32
本文介绍了空字段不应存储到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

空字段不应存储到数据库中

本文发布于:2023-10-28 19:11:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537530.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不应   字段   数据库中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!