Null Page_Validators在触发asp按钮onclick时导致错误

时间:2015-09-08 15:33:49

标签: javascript asp.net validation onclick

我有一个asp按钮,提交一个带有后端验证的表单

<asp:button id="btnAdd" visible="true" runat="server" ValidationGroup="ETAFAdd"  text="Add &#187;" CssClass="formBut addEmailButton" causesvalidation="true" />
                    &nbsp; <a id="hoverover" style="cursor:default;" onmouseover="ShowPopup(this);" onmouseout="HidePopup();">

及其提交的字段:

<td valign="top">
    <asp:textbox id="txtToName" CssClass="iField txtToName" runat="server" ValidationGroup="ETAFAdd" />
    <asp:RequiredFieldValidator runat="server" ID="rfvToName"
        ControlToValidate="txtToName"
        ValidationGroup="ETAFAdd"   
        Display="Dynamic"
        ErrorMessage="<b>Required Field Missing</b><br />A name is required." />  
    <ajaxToolkit:ValidatorCalloutExtender runat="Server" ID="vceToName"
        TargetControlID="rfvToName"
        HighlightCssClass="validatorCalloutHighlight" /> 
</td>
<td valign="top">
    <asp:textbox id="txtToEmail" CssClass="iField txtToEmail" runat="server" ValidationGroup="ETAFAdd"/>
    <asp:RequiredFieldValidator runat="server" ID="rfvToEmail"
        ControlToValidate="txtToEmail"
        ValidationGroup="ETAFAdd"
        Display="Dynamic"
        ErrorMessage="<b>The email address you entered is invalid.</b><br />Example: name@wimco.com" />  
    <ajaxToolkit:ValidatorCalloutExtender runat="Server" ID="vceToEmail"
        TargetControlID="rfvToEmail"
        HighlightCssClass="validatorCalloutHighlight" /> 
</td>

当我点击asp按钮时,它可以工作。我尝试在页面上添加另一个按钮,触发带有onclick的asp按钮

$(".formBut.addEmailButton").click();

然后在ScriptResource验证中发生javascript错误;前两个Page_Validators为null,我不确定原因,并且这些null对象会抛出错误。这是尝试运行的函数:

function Page_ClientValidate(validationGroup) {
Page_InvalidControlToBeFocused = null;
if (typeof(Page_Validators) == "undefined") {
    return true;
}
var i;
for (i = 0; i < Page_Validators.length; i++) {
    ValidatorValidate(Page_Validators[i], validationGroup, null);
}
ValidatorUpdateIsValid();
ValidationSummaryOnSubmit(validationGroup);
Page_BlockSubmit = !Page_IsValid;
return Page_IsValid;
}

null Page_Validators来自哪里?

1 个答案:

答案 0 :(得分:0)

检查验证器是否为空。

MediaRecorder.AudioSource.VOICE_DOWNLINK