ASP.NET form with Submit and Cancel Button

Thynchype

New Member
I created a form inn ASP.NET .The code is shown below\[code\]<form id="AddSchool" method="post" runat="server"><span class="failureNotification"> <asp:Literal ID="ErrorMessage" runat="server" ></asp:Literal></span><asp:ValidationSummary ID="AddSchoolValidationSummary" runat="server" CssClass="failureNotification" ValidationGroup="AddSchoolValidationGroup"/><asp:Label ID="SchoolNameLabel" runat="server" Text="School Name " AssociatedControlID="SchoolName"></asp:Label><asp:TextBox ID="SchoolName" runat="server" Height="16px" Width="337px" CssClass="textEntry"></asp:TextBox><asp:Label ID="Label15" runat="server" Font-Size="Larger" ForeColor="Red" Text="*"></asp:Label><asp:RequiredFieldValidator ID="SchoolNameRequired" ControlToValidate="SchoolName" CssClass="failureNotification" runat="server" ErrorMessage="School Name is Required" ToolTip="School Name is Required" ValidationGroup="AddSchoolValidationGroup"></asp:RequiredFieldValidator><asp:Label ID="StreetAddressLabel" runat="server" Text="Street Address " AssociatedControlID="StreetAddress"></asp:Label><asp:TextBox ID="StreetAddress" runat="server" Height="16px" Width="338px" CssClass="textEntry"></asp:TextBox><asp:Label ID="Label16" runat="server" Font-Size="Larger" ForeColor="Red" Text="*"></asp:Label><asp:RequiredFieldValidator ID="StreetAddressRequired" ControlToValidate="StreetAddress" CssClass="failureNotification" runat="server" ErrorMessage="Street Address is Required" ToolTip="Street Address is Required" ValidationGroup="AddSchoolValidationGroup"></asp:RequiredFieldValidator><asp:Label ID="CityLabel" runat="server" Text="City " AssociatedControlID="City" ></asp:Label><asp:TextBox ID="City" runat="server" Height="16px" Width="340px" style="margin-left: 0px" CssClass="textEntry"></asp:TextBox><asp:RequiredFieldValidator ID="CityRequired" runat="server" ControlToValidate="City" CssClass="failureNotification" ErrorMessage="City is Required" ToolTip="City is Required" ValidationGroup="AddSchoolValidationGroup"></asp:RequiredFieldValidator><asp:Label ID="StateLabel" runat="server" Text="State " AssociatedControlID="StateList"></asp:Label><asp:DropDownList ID="StateList" runat="server" Height="25px" Width="119px" DataSourceID="SqlDataSource1" DataTextField="StateName" DataValueField="StateName" CssClass="textEntry"> <asp:ListItem>Select A State</asp:ListItem></asp:DropDownList><asp:Label ID="Label17" runat="server" Font-Size="Larger" ForeColor="Red" Text="*"></asp:Label><asp:RequiredFieldValidator ID="StateRequired" runat="server" Display="Dynamic" ControlToValidate="StateList" CssClass="failureNotification" ErrorMessage="A State is Required" ToolTip="A State is Required" ValidationGroup="AddSchoolValidationGroup"></asp:RequiredFieldValidator><asp:Label ID="ZipLabel" runat="server" Text="Zip Code :" AssociatedControlID="ZipCode"></asp:Label><asp:TextBox ID="ZipCode" runat="server" Width="139px" CssClass="textEntry"></asp:TextBox><asp:RequiredFieldValidator ID="ZipCodeRequired" runat="server" ControlToValidate="ZipCode" CssClass="failureNotification" ErrorMessage="Zip Code is Required" ToolTip="Zip Code is Required" ValidationGroup="AddSchoolValidationGroup"></asp:RequiredFieldValidator><asp:Label ID="EmailLabel" runat="server" Text="Email Address" AssociatedControlID="Email"></asp:Label>:<asp:TextBox ID="Email" runat="server" Width="304px" Height="16px" CssClass="textEntry"></asp:TextBox><asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email" CssClass="failureNotification" ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="AddSchoolValidationGroup">*</asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="EmailFormat" runat="server" ControlToValidate="Email" CssClass="failureNotification" ErrorMessage="The email address entered does not appear to be valid." ValidationGroup="AddSchoolValidationGroup" ValidationExpression="([A-Z]|[a-z]|[0-9])+[@]([A-Z]|[a-z]|[0-9])+\.([A-Z]|[a-z]){2,6}" Display="Dynamic">*</asp:RegularExpressionValidator> <asp:Label ID="ConfirmEmailLabel" runat="server" Text="Confirm Email Address " AssociatedControlID="ConfirmEmail"></asp:Label>:<asp:TextBox ID="ConfirmEmail" runat="server" Height="18px" Width="304px" CssClass="textEntry"></asp:TextBox><asp:RequiredFieldValidator ID="ConfirmEmailRequired" runat="server" ControlToValidate="ConfirmEmail" CssClass="failureNotification" ErrorMessage="Confirm E-mail is required." ToolTip="Confirm E-mail is required." ValidationGroup="AddschoolValidationGroup">*</asp:RequiredFieldValidator><asp:CompareValidator ID="EmailCompare" runat="server" ControlToCompare="Email" ControlToValidate="ConfirmEmail" CssClass="failureNotification" Display="Dynamic" ErrorMessage="E-mail and Confirm E-mail must match." ValidationGroup="AddSchoolValidationGroup">*</asp:CompareValidator><asp:Label ID="Label14" runat="server" ForeColor="Red" Text="* = Required"></asp:Label><asp:ImageButton ID="Cancel" runat="server" OnClick="cancelClick" ImageUrl="~/Styles/images/cancel-btn.png" /><asp:ImageButton ID="Submit" runat="server" OnClick="submitClick" ImageUrl="~/Styles/images/submit-btn.png" /></form>\[/code\]This form contains some fields like School name,street address,city,email,conform email etc..Along with Asp.net validation controls and two image buttons, one is named as cancel and other is named as submit.When i click on submit i want to validate the form using that validation controls and raise an event "submitclick".And when i click on cancel i want to raise an event cancelclick.Can anyone explain how to validate the form when i click submit 'image button'.
 
Back
Top