UserControl中的CustomValidator不适用于客户端验证

时间:2019-04-04 16:30:12

标签: asp.net webforms

我有一个问题,我们可以创建一个customvalidator并在用户控件中使用clientvalidation方法。因为就我而言,我正在尝试这样做,但是找不到在用户控件.ascx文件中编写的javascript方法。

我的自定义控件:

    <script language="javascript" type="text/javascript">
    function CheckBoxRequired_ClientValidate(sender, e) {
        e.IsValid = ($("#<%= cb_lowbloodsugar.ClientID %>").is(':checked') || $("#<%= cb_hibloodsugar.ClientID %>").is(':checked'));
            }

</script>
<div class="col-xs-12 col-sm-6">
   <asp:RadioButton GroupName="diabetesTriggs" ID="cb_lowbloodsugar" runat="server" Text="RB_1"></asp:RadioButton>
</div>
<div class="col-xs-12 col-sm-6">
    <asp:RadioButton GroupName="diabetesTriggs" ID="cb_hibloodsugar" runat="server" Text="RB_2"></asp:RadioButton>
</div>
<div class="col-xs-12">
    <asp:CustomValidator runat="server" ID="CheckBoxRequired" SetFocusOnError="true" BorderColor="red" EnableClientScript="true" ErrorMessage="Select atleast One of the Triggers" ClientValidationFunction="CheckBoxRequired_ClientValidate" Display="Dynamic">
    </asp:CustomValidator>
 </div>

在我的窗体中使用了具有“保存”按钮的用户控件。

 <div class="row">
     <uc1:Known_Triggers ID="known_triggers" runat="server"> 
     </uc1:Known_Triggers>
 </div>
 <asp:LinkButton ID="btnSaveForm" CausesValidation="true" runat="server" ToolTip="" Text="Save as Draft"></asp:LinkButton>

有人可以告诉我我在哪里做错了吗?当我单击“保存”按钮时,它会引发错误:

Uncaught SyntaxError: Unexpected token .
at HTMLSpanElement.CustomValidatorEvaluateIsValid [as evaluationfunction] (ScriptResource.axd?d=AWeHWDQe8GyVu9f2X0L-rbZdk3zyZz41x8G8Gb2ap0h6w5bV2AKnMAPivdaTMm46et3mGhJVN4VRQ95d4TgoZnSTA_E-l_eTx_QIN0vmzDpPLldL9cFtb6GKZ_rSFmkgrIqCJu2rce0jFi4bRaBB1ZNA8wQ1&t=b343795:458)
at ValidatorValidate (ScriptResource.axd?d=AWeHWDQe8GyVu9f2X0L-rbZdk3zyZz41x8G8Gb2ap0h6w5bV2AKnMAPivdaTMm46et3mGhJVN4VRQ95d4TgoZnSTA_E-l_eTx_QIN0vmzDpPLldL9cFtb6GKZ_rSFmkgrIqCJu2rce0jFi4bRaBB1ZNA8wQ1&t=b343795:208)
at Page_ClientValidate (ScriptResource.axd?d=AWeHWDQe8GyVu9f2X0L-rbZdk3zyZz41x8G8Gb2ap0h6w5bV2AKnMAPivdaTMm46et3mGhJVN4VRQ95d4TgoZnSTA_E-l_eTx_QIN0vmzDpPLldL9cFtb6GKZ_rSFmkgrIqCJu2rce0jFi4bRaBB1ZNA8wQ1&t=b343795:128)
at Sys$WebForms$PageRequestManager.WebForm_DoPostBackWithOptions [as _originalDoPostBackWithOptions] (WebResource.axd?d=lPkeD9ZzZ0Ih-dHXFVKRQgRKOSuzEtxKvDc7l0fJ764kJAK87A6Ll7YLyUyPgNuOUeS7sAXlafI2Pq871LfCV8YBmn01&t=636558592200000000:14)
at Sys$WebForms$PageRequestManager$_doPostBackWithOptions [as _doPostBackWithOptions] (ScriptResource.axd?d=nmEi14WMbBbjuIytG1JpxED4VGMC47kaH3kkbIYY1FygTFS1aZv06_lCcO1m91pZN-EdykYMS2zNJcubZsrgJMsKcuRssGL0VaK1S5D3eMmvQDnGW-GoZRc8yqELBfIO5SmNPDtLUTPUpkDAjdeQfPFh7I1e9neZT7I5tYVINEx0Mt_f0&t=ffffffffcae7840d:488)
at ScriptResource.axd?d=JXWLliCCnPj7a93KnjUeKevxVS00qxDBPm_IUfaF8s74g6Xv_9yb9ezrQOcHPFaXvxlSZIgVZjYlhHyH1SMHSm23VybVgF9karBAlwAwdgYa_L05IrESzEvUzsPwdgYysOXfUToQg3qDCjW4VkvAlVf7YKaOvB54fhyB9RlyUIyR3xPX0&t=ffffffffcae7840d:47
at <anonymous>:1:1

0 个答案:

没有答案