Watch this example on YouTube:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ValidationGroups.aspx.cs" Inherits="WebApplication1.ValidationGroups" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script lang="javascript">
function ValidateClose() {
var result = Page_ClientValidate('SubmitValidation');
if (result) {
result = Page_ClientValidate('SaveValidation');
}
return result;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Submit - Update" ValidationGroup="SubmitValidation"/>
<asp:Button ID="Button2" runat="server" Text="Save" OnClientClick="return ValidateClose();" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Text Box 1 is required"
ControlToValidate="TextBox1" ValidationGroup="SubmitValidation"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ErrorMessage="Text Box 2 is required"
ControlToValidate="TextBox2" ValidationGroup="SaveValidation" ></asp:RequiredFieldValidator>
</div>
</form>
</body>
</html>
No comments:
Post a Comment