我的网站上有几个文本框,每个文本框都有一个必填字段验证器,底部有一个提交按钮。无论我是否在文本框中输入了值,提交按钮都有效。以下是代码:
<asp:TextBox ID="TextBoxName" ValidationGroup="textgroup" runat="server"
ToolTip="Insert the Pokemon's name" CssClass="upper-case" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ValidationGroup="textgroup" Text="Names only please" ControlToValidate="TextBoxName"
ValidationExpression="^[a-zA-Z]*$" CssClass="required-field" />
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="textgroup"
runat="server" Text="Required Field" ControlToValidate="TextBoxName"
CssClass="required-field" />
<br />
这是提交按钮:
<asp:Button ID="Button1" runat="server" Text="Insert Card" ValidationGroup="textgroup" />
提交按钮的代码隐藏:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Page.Validate()
CardCollectionDataSource.Insert()