Problem with execute two query functions in asp.net webform code behind

Viewed 37

I have a box to wait for and I want the box to be displayed first and removed after 5 seconds. I wrote two jquery function for him One for show and one for no show The first function works correctly But when I call the second function, the principles of the first function do not work and none of the functions are executed.

protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "OpenWaitingPagePopup()", true);
        System.Threading.Thread.Sleep(5000);
        Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction2", "CloseWaitingPagePopup()", true);
    }

and my jquery functios is :

 <script type="text/javascript">
        function OpenWaitingPagePopup() {
            $(".waiting-loader-layer").fadeIn("fast");
        }
        function CloseWaitingPagePopup() {
            $(".waiting-loader-layer").fadeOut();
        }
</script>

and my waiting popup is :

  <!-- waiting popup -->
  <div class="waiting-loader-layer">
   <div class="inner">
    <img src="https://www.pekbag.ir/images/ajax-loader-cs.gif" width="50" height="50">
    <span> Please wait ... </span>
</div>
 </div>

The jQuery file has also been added to the page correctly.

2 Answers

This functions on Page Load

Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "OpenWaitingPagePopup()", true);
System.Threading.Thread.Sleep(5000);
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction2", "CloseWaitingPagePopup()", true);

they called with a delay of 5 seconds, but the delay is on server side, not on client side. The results of those is to render at the same time the two calls (show and hide) on browser - so its not working as you believe.

You must find an alternative way for your wait and must be on client side.

Related