1
.Net検証を使用してフォームを検証しています。問題は、[送信]をクリックしたときにフォームが検証されているかどうかをチェックしないことです。フィールドが空白の場合でも、アラートが発生します。私はフォームが検証された後にのみ警告を発するようにしたい。ありがとうございました。Clickイベントを呼び出す前に.Net ValidationがTrueであるかどうかを確認する方法
<asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="error-box" />
<asp:Label ID="empLast4Lbl" runat="server" Text="Last 4 digits of SSN#">Last 4 digits of SSN</asp:Label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="empLast4Txt"
ErrorMessage="Last 4 digits of SSN is required." ForeColor="Red" CssClass="float-none">*</asp:RequiredFieldValidator>
<asp:TextBox ID="empLast4Txt" runat="server"></asp:TextBox>
<asp:Label ID="empDobLbl" runat="server" Text="Label">Date of Birth</asp:Label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="empDobTxt"
ErrorMessage="Date of Birth is required." ForeColor="Red" CssClass="float-none">*</asp:RequiredFieldValidator>
<asp:TextBox ID="empDobTxt" runat="server"></asp:TextBox>
<asp:Button ID="submitEmp" runat="server" Text="Submit" Class="ap-webmethod" />
// jQueryの
$(".ap-webmethod").click(function() {
alert("Fired");
});