ASP.net declarative programming approach, the Page.IsValid method is something easy to forget.
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="MyValidationGroup">asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="This
field is required!" ValidationGroup="MyValidationGroup">asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="Button"
ValidationGroup="MyValidationGroup" CausesValidation="true" />
<br />
<br />
<asp:TextBox ID="TextBox2" runat="server" ValidationGroup="AnotherValidationGroup">asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="This
field is required!" ValidationGroup="AnotherValidationGroup">asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button2" runat="server" Text="Button" ValidationGroup="AnotherValidationGroup"
OnClick="Button2_Click" />
protected void Button2_Click(object sender, EventArgs e) {
Page.Validate("MyValidationGroup");
if (!Page.IsValid) {
return;
}
Response.Write("Button was clicked at " + DateTime.Now.ToShortTimeString());
}
0 comments:
Post a Comment