SharePoint Pals
 | Sign In
How to Make a Feel that the Page Loads Asynchronous in SharePoint 2013
by Sathish Nadarajan 28 Oct 2014
Author
SharePoint MVP
Visits   
Today  :   5     Total  :    9533

I had an Application page which will open as a Modal Dialog, comprises 2 List boxes, so that the user can toggle the Items from Source to Target and vice versa.

The screen will looks like below.

clip_image002

The entire screen will looks like

clip_image004

If the content on the List box becomes huge, then the page itself, freezes while loading. i.e., the User will see a blank page until all the List Items are rendered on the List Box. This, we can see, if there are around 1000, 2000 items on the List box. To give a better user experience, we thought of giving an Asynchronous feel. Not exactly the Asynchronous Loading. But, a feel that the page loads asynchronously. To accomplish this,

The overall approach followed are as follows.

1. Create 2 divs

2. One having a text like “Loading…”

3. The second one is the actual content div.

4. Keep a hidden button.

5. On the Page_Load, don’t write anything.

6. On the Click event of the hidden button, load the List boxes.

7. On the Click event from the document.ready event.

8. Hence, when the page loads, no load is given to the system. Hence, the page loads with the Loading DIV Tag.

9. And once the page loads, then the Click event gets triggered. Then the actual loading happens. Till the time, the User will be seeing a “Loading…” Message.

clip_image006

Now, let us see the HTML code for this.

 <div class="loading">Loading...</div>
     <div class=" content invisible " style="padding-top: 10px; width: 610px;">
 
         <fieldset>
             <legend>Add Pages</legend>
             <table style="width: 600px; margin-top: 20px;">
                 <tr>
                     <td colspan="2">
                         <div class="selectDeptBox">
                             <div class="deptSelHeader padding17">Source</div>
                             <asp:ListBox ID="lstSource" runat="server" CssClass="itemYScroll" SelectionMode="Multiple" Height="220px"></asp:ListBox>
                         </div>
 
                         <div class="selectDeptBut">
  
                             <asp:Button ID="btnMoveRight" Font-Bold="true" runat="server" Text=">>" OnClick="btnMoveRight_Click" />
                             <div class="clearboth" style="padding-top: 10px"></div>
                              
                             <asp:Button ID="btnMoveLeft" Font-Bold="true" runat="server" Text="<<" OnClick="btnMoveLeft_Click" />
                             <div class="clearboth" style="padding-top: 10px"></div>
 
                         </div>
 
 
 
                         <div class="selectDeptBox">
                             <div class="deptSelHeader padding17">Target</div>
                             <asp:ListBox ID="lstTarget" runat="server" CssClass="itemYScroll" SelectionMode="Multiple" Height="220px"></asp:ListBox>
                         </div>
 
                     </td>
                 </tr>
 
 
 
             </table>
             <br />
 
 
             <div style="width: 100px; margin-left: 220px;">
                  
                  
                 <asp:Button ID="bthRefresh" runat="server" Text="" OnClick="bthRefresh_Click" CssClass="invisible" ClientIDMode="Static" />
             </div>
             <br />
         </fieldset>
          
         <asp:HiddenField ID="hdnHasLoaded" runat="server" Value="false" ClientIDMode="Static" />
          
 
     </div>
 

And the CSS is as follows.

 <style>
 .ace-hidden {
             display: none;
         }
 
         .ace-invisible {
             visibility: hidden;
         }
     </style>
 
 

The Javascript to trigger the Events are

 $(document).ready(function ($) {
 
             var $hasLoaded = $("#hdnHasLoaded");
                 if ($hasLoaded.val() === "false") {
                     $("#txtRelatedPages").val($(".ace-relatedpages-value", window.parent.document).val());
                     $hasLoaded.val("true");
                     $("#bthRefresh").click();
                     return;
                 }
 
                 $(".ace-content").removeClass("ace-invisible");
                 $(".ace-loading").remove();
                 $("#btnUpdate").click(relatedPagesManager.save);
         });
 

The C# (Server Side) code to render the List boxes are as follows.

 protected void Page_Load(object sender, EventArgs e)
         {
         }
 
         protected void bthRefresh_Click(object sender, EventArgs e)
         {
             try
             {
                // Actually Bind the List boxes here.
             }
             catch (Exception ex)
             {
                 }
         }
 

Note:

Here we are making the Page to load first. Then, Bind the values on the appropriate controls. By this way, we are eliminating the feel of delay in page load. The above code is nowhere increases the performance. Just the feel for the end user. Instead of waiting for the page to load, the user can see a “Loading” information. The same can be done with the Loading.gif also. We can see in upcoming articles more about this. And on the next Article, let us see, how to create an Asynchronous WebPart itself. That will definitely increases the performance. It is a kind of Multi Threading Operation.

Happy Coding.

Sathish Nadarajan.

blog comments powered by Disqus

SharePoint Pals

Pals
SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile

Training

Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community




SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to articles@sharepointpals.com in a word document.

Related Resources

Recent Tweets

Twitter January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart https://t.co/VxSi4QnNrC

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window https://t.co/EQ7HkoZDkX

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features https://t.co/zAXObHCFpH

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013 https://t.co/LEwnUoI7EY

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services https://t.co/Yvp2VPFIRP

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation