我創建了一個表格客棧ASP.NET .The代碼如下所示與提交和取消按鈕ASP.NET表單
<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>
這種形式包含了諸如學校名稱,街道地址,城市,電子郵件某些領域,符合電子郵件等。隨着Asp.net驗證控件和兩個圖像按鈕,一個被命名爲取消和其他被命名爲submit.When我點擊提交我想驗證使用該驗證控件的形式,並提出一個事件「submitclick」 。當我點擊取消我想提出一個事件cancelclick.Can任何人都可以解釋如何驗證表單時,我點擊提交'圖像按鈕'。
是的,先生..確保..謝謝你的指導... – aji136252