私のページには、さまざまな種類の ASP.NET バリデーターが多数あります。そのうちのいくつかは、ページでのユーザーの選択に応じて、javascript を使用して無効にしています。
$.each(Page_Validators, function(index, validator)
{
if ($(validator).hasClass("pain")) {
ValidatorEnable(validator, false);
}
});
これは機能しているようで、バリデーターは、他のバリデータータイプを使用できない場合に使用している CustomValidators を除いて、すべての場合に起動しません。
<asp:CheckBoxList id="BodyPartsList" runat="server" RepeatColumns = "2"
Width="1023px">
<asp:ListItem Text = "0. Head/headaches" Value = "1"></asp:ListItem>
<asp:ListItem Text = "1. Leg(s)" Value = "2"></asp:ListItem>
<asp:ListItem Text = "2. Arm(s)" Value = "3"></asp:ListItem>
<asp:ListItem Text = "3. Neck" Value = "4"></asp:ListItem>
<asp:ListItem Text = "4. Shoulder(s)" Value = "5"></asp:ListItem>
<asp:ListItem Text = "5. Low Back" Value = "6"></asp:ListItem>
<asp:ListItem Text = "6. Upper Back" Value = "7"></asp:ListItem>
<asp:ListItem Text = "7. Feet" Value = "8"></asp:ListItem>
<asp:ListItem Text = "8. Hand(s)" Value = "9"></asp:ListItem>
<asp:ListItem Text = "9. Other(Describe in "Details of Plan")" Value = "10"></asp:ListItem>
</asp:CheckBoxList>
<asp:CustomValidator ID="PainLocationValidator" runat="server" Display="Dynamic"
ErrorMessage="Location of pain is required."
ClientValidationFunction="checkPainListValidate"
ValidationGroup = "OnSave" EnableClientScript= "true" SetFocusOnError= "true" Width = "100%" CssClass = "pain" />
function checkPainListValidate(sender, args) {
args.IsValid = true;
if ($('#<%= BodyPartsList.ClientID %> input:checked').length > 0)
args.IsValid = true;
else
args.IsValid = false;
}
なぜこうなった?それらを無効にするために他にできることはありますか?
ありがとう。