簡體   English   中英

SetTimeOut和回發發生后如何關閉模式

[英]How to close the modal after SetTimeOut and postback occurred

這是我的問題:在我的網頁中,當用戶單擊“提交”按鈕時,我有一個用於發送電子郵件和“提交”按鈕的文本框。這種過程需要一點時間,所以我考慮向用戶顯示一個模態窗口,盡管過程已經完成,但在我給模態顯示窗口的時間量之后,事情就已經發生了。

我的問題是在發生模態和回發的SetTimeout后如何關閉模態???

這是我的代碼,並鏈接到對我有幫助的代碼。 http://www.aspsnippets.com/Articles/Display-loading-progress-image-when-Page-Loads-or-does-PostBack-using-ASPNet.aspx

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

      function ShowProgress() {
            setTimeout(function () {
                var modal = $('<div />');
                modal.addClass("modal");
                $('body').append(modal);
                var loading = $(".loading");
                loading.show();
                var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
                var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
                loading.css({ top: top, left: left });
            }, 200);
            __doPostBack("<%=btnSubmit.UniqueID %>", "");
             // How to close the modal after 200 sec are over and postback been execute 
        }



   Email:<asp:TextBox name="Email" ID="txtemail" ValidationGroup="Group" runat="server"  Width="330px"/>

                    <asp:RequiredFieldValidator ID="requiredFieldValidatorEmail" runat="server" ControlToValidate="txtemail"
                        Display="Dynamic" ErrorMessage="Req" ForeColor="Red" SetFocusOnError="True" ValidationGroup="Group"
                        CssClass="validationClass"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="revEmail" runat="server" ErrorMessage="Please Enter Valid Email"
                        ValidationGroup="vgSubmit" ControlToValidate="txtEmail" CssClass="requiredFieldValidateStyle"
                        ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"> </asp:RegularExpressionValidator>
                              <asp:Button ID="btnSubmit" ValidationGroup="Group" runat="server" Text="Submit" OnClick="passwordSubmit_Click"   OnClientClick="ShowProgress();"/>
                              <div class="loading" align="center">
                                Loading. Please wait.<br />
                                <br />
                                <img src="Images/Layout/ajax-loader.gif" alt="" />
                              </div>
<style type="text/css">
       .modal
        {
            position: fixed;
            top: 0;
            left: 0;
            background-color: black;
            z-index: 99;
            opacity: 0.8;
            filter: alpha(opacity=80);
            -moz-opacity: 0.8;
            min-height: 100%;
            width: 100%;
        }
        .loading
        {
            font-family: Arial;
            font-size: 10pt;
            border: 5px solid #808080;
            width: 200px;
            height: 100px;
            display: none;
            position: fixed;
            background-color: White;
            z-index: 999;
        }
     </style>

后面的代碼:

 Protected Sub passwordSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
        If revEmail.IsValid Then
            Dim dba As New DBAccess
            Dim email As String = ""
            Dim password As String = ""

            Dim ds As DataSet = dba.GetForgotPasswordEmail(m_UserName, txtemail.Text, m_CompanyCode)
            If Not ds Is Nothing Then

                Dim dr As DataRow = ds.Tables(0).Rows(0)
                email = dr("Email")
                password = dr("Password")
                Dim fpMessage As New SendForgotEmailPassword
                fpMessage.SendForgotPasswordEmail(email, password)
                lblEmailSent.Text = "Email has been sent."
                lbToLoginPage.Visible = True

            Else
                lblEmailSent.Text = "No Such Email."
                lbToLoginPage.Visible = True
            End If
        Else
            lbToLoginPage.Visible = False
        End If
    End Sub

您應該在回發中添加回調

function ShowProgress() {

        // I guess it shows your modal
        setTimeout(function () {
            var modal = $('<div />');
            modal.addClass("modal");
            $('body').append(modal);
            var loading = $(".loading");
            loading.show();
            var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
            var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
            loading.css({ top: top, left: left });
        }, 200);

        // Gets the request manager
        var requestManager = Sys.WebForms.PageRequestManager.getInstance();

        // Callback function will be called after __doPostBack
        function EndRequestHandler(sender, args) {
            // This will be executed after __doPostBack
            // Here's you should put your code to close modal!

            // Remove the request handler
            requestManager.remove_endRequest(EndRequestHandler);
        }

        // Tells the request manager we are adding a callback
        requestManager.add_endRequest(EndRequestHandler);

        __doPostBack("<%=btnSubmit.UniqueID %>", "");

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM