且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-06-03 03:21:05

尝试以下示例,看看我如何使用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.