Showing results after a SharePoint Longrunning operation on the same page

To be honest, this is quite a hack, however it can still be used on SHP2010 and SHP2013.

The basic idea is to do the following :

  • In page_load create an SPLongOperation
  • Let the operation Begin
  • Execute the Database call in the operation
  • Do not provide an end on the operation, so it won’t redirect
  • Add javascript to the bottom of the page
//This code goes into the code-behind of the application page
 public string WindowTitle
        {
            get
            {
                return SPEncode.HtmlEncode(SPContext.Current.ListItem.Title);
            }
        }

 protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.EnsureChildControls();
                using (SPLongOperation lng = new SPLongOperation(this.Page))
                {
                    //Custom Messages on the Spinning Wheel Screen
                    lng.LeadingHTML = "Loading items from DB...";
                    lng.TrailingHTML = "Please wait while items are loaded...";
                    //Start the long operation
                    lng.Begin();

                    LoadItems();
                }
}

asp.net code add to bottom of the application page:

<script type="text/javascript">
        var gearsItem = document.getElementById('GearPage');
        if (gearsItem) {
            gearsItem.style.display = 'none';
            document.title = '<%=WindowTitle %>'; //set the title of the page to the title of the Current SPListItem
        }
    </script>

I’ve done this in a SharePoint modal window, the result is that the database resultset is shown in the same modal window without the need to redirect the user to a results page!

This is shown while the data is loading :
data2

Then this is shown once the data has loaded :
data1

Leave a comment