Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BlockUI when using a popup from serverside

I am using an UpdatePanel to block the UI on a long process, my problem that is it works when I put a simple button, but when the button is within a popup it doesn't work(simply gets stuck untill the process is done without blocking the ui).

Code that works:

<asp:UpdatePanel runat="server" ID="updatePanel">
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="lb_start" />
  </Triggers>
  <ContentTemplate>
      <asp:UpdateProgress runat="server" ID="upprogress" AssociatedUpdatePanelID="updatePanel" DisplayAfter="0">
            <ProgressTemplate>
                <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
                    <asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="~/images/iguloader-yashar.gif" AlternateText="Loading ..." ToolTip="Loading ..." Style="padding: 10px; position: fixed; top: 45%; left: 50%;" />
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <asp:LinkButton runat="server" ID="lb_start" class="btn btn-success" OnClick="lb_start_Click"><i class="fa fa-start"></i> Start</asp:LinkButton>            
  </ContentTemplate>
</asp:UpdatePanel>

Server side:

protected void lb_start_Click(object sender, EventArgs e)
{
    //long process
}

Code that doesn't work(Uses colorbox.js):

<asp:UpdatePanel runat="server" ID="updatePanel">
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="lb_start" />
  </Triggers>
  <ContentTemplate>
      <asp:UpdateProgress runat="server" ID="upprogress" AssociatedUpdatePanelID="updatePanel" DisplayAfter="0">
            <ProgressTemplate>
                <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
                    <asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="~/images/iguloader-yashar.gif" AlternateText="Loading ..." ToolTip="Loading ..." Style="padding: 10px; position: fixed; top: 45%; left: 50%;" />
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <a runat="server" id="a_start" class="inline" href="#startModal" title="Start scan"><span  class="btn btn-success"><i class="fa fa-play"></i></span></a>        
  </ContentTemplate>
</asp:UpdatePanel>

<div id="startModal" style="padding:10px; background:#fff;">
    <h2>Start Scan</h2>
    Click ok to continue:
        <asp:LinkButton runat="server" ID="lb_start" class="btn btn-success" OnClick="lb_start_Click"><i class="fa fa-start"></i> Start</asp:LinkButton>
</div>

Tried playing with it a little, Any ideas?

like image 363
omriman12 Avatar asked Jun 07 '15 07:06

omriman12


1 Answers

You can accomplish this task using a jQuery plugin known as blockui (funny enough).

This link here shows an example: https://gist.github.com/whoshotjr/3010693

Simply include the jquery.blockui.js available from http://malsup.com/jquery/block/

Then include this code in your project:

<script type="text/javascript">
        Page = Sys.WebForms.PageRequestManager.getInstance();
        Page.add_beginRequest(OnBeginRequest);
        Page.add_endRequest(endRequest);

        function OnBeginRequest(sender, args) {
            $.blockUI();
        }
        function endRequest(sender, args) {
            $.unblockUI();
        }

 </script>

Since you are running client side you'd almost always have to use Javascript to block UI while performing a web request. I've used a similar setup to this in MVC but it is all the same in the end. Hope this helps!

like image 193
Tyler Durden Avatar answered Oct 02 '22 16:10

Tyler Durden