locked
Call a JS function only if a postback is taking too long RRS feed

  • Question

  • User1310055179 posted

    Hi,

    I have a dynamic web form and in some cases the postback is taking a long time (e.g when connecting to a remote database).

    The postback triggers a javascript function that enables a rendering gif and a div that blocks the user from editing the form.

    I would like to run this JS function only if the postback takes more than 1 second to run.

    This is my code:

    JS functions:

    function skm_LockScreen(str) 
            { 
                var lock = document.getElementById(str);
                if (lock) 
                    lock.className = 'LockOn';
            }
            
            function skm_unLockScreen(str) 
            { 
                var lock = document.getElementById(str);
                if (lock) 
                    lock.className = 'LockOff'; 
            }
    function pageLoad() 
            {
                skm_unLockScreen('skm_LockPane');
            }

    ASPX:

    <div id="skm_LockPane" class="LockOff" runat="server">
                <asp:Image ID="render_img" runat="server" ImageUrl ="~/Images/progress.gif" style=z-index:7000position:absolutetop:30%left:45%;  
                        height:60pxwidth60px; " />
            </div> 

    Codebehind:

    sTextBox.Attributes.Add("onchange""skm_LockScreen('skm_LockPane');");
    

    What is the best way to achieve it?

    Tuesday, July 3, 2018 6:49 AM

All replies

  • User-1171043462 posted

    Such thing is not possible.

    Reason.

    1. When you do a PostBack, it means request is sent and since HTTP is stateless, you won't know how much time it will take.
    2. Once PostBack is started, the Page is control is lost that means you cannot do anything once PostBack or Form Submission is started.
    Tuesday, July 3, 2018 7:39 AM