即使在关闭 ModalPopupExtender 后,RequiredFieldValidator 错误消息仍然存在

RequiredFieldValidator error message persists even after closing ModalPopupExtender

请帮助我的朋友, 我创建了 modalpopupextender,并在 mpe 内的文本框上使用 asp requirefieldvalidator。当我单击按钮提交时,rfv 已经出现。但是当我点击取消按钮时问题就来了。面板将关闭。但是当我再次单击 link mpe 时,错误消息仍然出现。这是我的代码:

<cc1:ModalPopupExtender ID="mpeSignUp"
    runat="server" PopupControlID="pnlPopupSignUp"
    TargetControlID="lnkButtonSignUp"
    CancelControlID="btnCancelSignUp"
    OnCancelScript="DoCancel()" 
    DropShadow="true" BackgroundCssClass="modalBackground">
 </cc1:ModalPopupExtender>

<asp:Panel ID="pnlPopupSignUp" runat="server" CssClass="modalPopupSignUp" Style="display: none">
    <asp:TextBox ID="txtUsername" runat="server" CssClass="twitterStyleTextbox" plceholder="Username" /> 
    <asp:RequiredFieldValidator ID="rfvtxtUsername" ErrorMessage="Required" ForeColor="Red" ControlToValidate="txtUsername" runat="server" EnableClientScript="false" /> <br />


<script type="text/javascript">
 function DoCancel() {
     $get('<%=txtEmail.ClientID%>').value = "";
     $get('<%=txtPassword.ClientID%>').value = "";
     $get('<%=txtUsername.ClientID%>').value = "";
     $get('<%=txtPasswordSignUp.ClientID%>').value = "";
     $get('<%=txtConfirmPasswordSignUp.ClientID%>').value = "";
     $get('<%=txtEmailSignUp.ClientID%>').value = "";
}
</script> 

隐藏代码:

Protected Sub btnSignUp_Click(sender As Object, e As EventArgs) Handles btnSignUp.Click

    mpeSignUp.Show()

End Sub

如果您的 aspx 中没有更新面板,您应该尝试使用一个并尝试使用 asynpostbacktrigger 触发:

示例未测试:

<asp:UpdatePanel ID="UpdatePanel1" CssClass="popup"  runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
    <ContentTemplate>
        <cc1:ModalPopupExtender ID="mpeSignUp"
            runat="server" PopupControlID="pnlPopupSignUp"
            TargetControlID="lnkButtonSignUp"
            CancelControlID="btnCancelSignUp"
            OnCancelScript="DoCancel()" 
            DropShadow="true" BackgroundCssClass="modalBackground">
         </cc1:ModalPopupExtender>

        <asp:Panel ID="pnlPopupSignUp" runat="server" CssClass="modalPopupSignUp" Style="display: none">
            <asp:TextBox ID="txtUsername" runat="server" CssClass="twitterStyleTextbox" plceholder="Username" /> 
            <asp:RequiredFieldValidator ID="rfvtxtUsername" ErrorMessage="Required" ForeColor="Red" ControlToValidate="txtUsername" runat="server" EnableClientScript="false" /> <br />

    </ContentTemplate>
    <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnCancelSignUp" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

希望对您有所帮助!

我已经找到了答案,谢谢@jomsk1e。

我在 js 上添加了这段代码:

document.getElementById('<%=rfvtxtUsername.ClientID%>').innerHTML = "";
document.getElementById('<%=rfvtxtPasswordSignUp.ClientID%>').innerHTML = "";
document.getElementById('<%=rfvtxtEmailSignUp.ClientID%>').innerHTML = "";