为什么ScriptManager在ASP中导致RequiredFieldValidator回发?. NET (Web F

本文关键字:回发 NET Web RequiredFieldValidator ScriptManager ASP 为什么 | 更新日期: 2023-09-27 18:07:03

在添加ScriptManager之前,当我点击登录按钮时,它显示了所需的字段警告,没有页面postback,但之后它已经开始先做postback,然后验证字段。

当页面上有UpdatePanel时,需要添加ScriptManager

我怎么能解决这个问题,使它不postbackRequiredFieldValidator ?

登录页面

<form id="signinform" runat="server" defaultfocus="username" defaultbutton="LogInBtn">
    <asp:scriptmanager id="FormScriptManager" runat="server"></asp:scriptmanager>
    <div class="form-signup">
        <div class="form-group form-group-info">
            <div class="append-icon m-b-30">
                <asp:textbox id="username" runat="server" cssclass="form-control c-white form-control-success" placeholder="Username" />
                <i class="mdi-action-perm-identity c-light"></i>
                <asp:requiredfieldvalidator runat="server" id="UserNameValidator" controltovalidate="username" display="Dynamic" validationgroup="LoginVAL" setfocusonerror="true" cssclass=" f-11 c-red m-b-0" errormessage="The username is required." />
            </div>
        </div>
        <div class="form-group form-group-info">
            <div class="append-icon m-b-30">
                <asp:textbox id="Password" textmode="Password" runat="server" cssclass="form-control c-white form-control-success" placeholder="Password" />
                <i class=" mdi-action-lock-outline c-light"></i>
                <asp:requiredfieldvalidator runat="server" id="PasswordValidator" controltovalidate="Password" display="Dynamic" setfocusonerror="true" validationgroup="LoginVAL" cssclass="f-11 c-red m-b-0" errormessage="The password is required." />
            </div>
        </div>
        <div class="togglebutton togglebutton-info">
            <label class="c-light normal f-11 m-b-15">
                <input type="checkbox" runat="server" name="RememberMe" id="RememberMe" class="md-checkbox">
                Remember me?
            </label>
        </div>
    </div>
    <asp:placeholder runat="server" id="ErrorMessage" visible="false" viewstatemode="Disabled">
        <p id="ErrorMessageContainer" runat="server" class="badge badge-danger m-b-5 f-11">
            <asp:Literal runat="server" ID="FailureText" ViewStateMode="Disabled" />
        </p>
    </asp:placeholder>
    <div class="progress-demo">
        <asp:linkbutton id="LogInBtn" runat="server" onclick="LogIn" text="Login" cssclass="btn btn-material-indigo btn-block btn-embossed ladda-button" validationgroup="LoginVAL" data-style="zoom-in"></asp:linkbutton>
    </div>
    <p>
        <%--   Enable this once you have account confirmation enabled for password reset functionality--%>
        <asp:hyperlink runat="server" id="ForgotPasswordHyperLink" viewstatemode="Disabled">Forgot your password?</asp:hyperlink>
    </p>

    <div class="modal fade" id="LoginModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog">
            <div class="modal-content">
                <div id="LoginModalHeader" runat="server" class="modal-header bg-aero">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="icons-office-52"></i></button>
                    <h4 class="modal-title c-white">
                        <asp:label id="LoginModalTitle" runat="server" />
                    </h4>
                </div>
                <asp:updatepanel id="LoginModalUpdatePanel" runat="server">
                    <ContentTemplate>
                        <div class="modal-body m-t-10">
                            <p class=" c-gray w-300 f-13"><asp:Label ID="LoginModalDetails" runat="server" /></p>
                        </div>
                        <div class="modal-footer">
                            <asp:LinkButton runat="server" ID="ResendConfirm" OnClick="SendEmailConfirmationToken" Text="Resend Confirmation" Visible="false" CssClass="btn btn-material-blue-grey btn-embossed" />
                            <button id="LoginModalCancel" runat="server" type="button" class="btn btn-default btn-embossed" data-dismiss="modal">Cancel</button>
                        </div>
                    </ContentTemplate>
                    </asp:updatepanel>
            </div>
        </div>
    </div>
</form>

我很感激你为解决我的问题所做的努力。

为什么ScriptManager在ASP中导致RequiredFieldValidator回发?. NET (Web F

我遇到了同样的问题一段时间后,能够通过Page.Validate();解决它。

基本上,在我添加ScriptManager之前,一切都运行良好。当我单击更新按钮时,字段验证器将运行并阻止回发,直到满足需求。在添加了ScriptManager标签之后,页面将返回,使我的验证器变得毫无用处。

我所做的是添加我的更新(提交)按钮点击事件:

page.validate();
if (Page.IsValid)
{
    // Your update or submit code here.
}

这似乎工作得很好!

这样写…

 <asp:updatepanel id="LoginModalUpdatePanel" runat="server">
 <ContentTemplate>
//paste all codes inside here 
</ContentTemplate>
</asp:updatepanel>