El Blanco's Office 2007 Blog

Thursday, September 13, 2007

An Issue with SPLongOperation

Two posts in one day ?! Not like me normally, but this one has been BUGGING me for absolutely ages and I've just solved it, so thought I'd share the solution here and now in case this had been bugging anyone else the same way it's been bugging me . . .

As most of you know, if you have some functionality on an application page that takes a while to execute you can wrap the functionality inside an SPLongOperation as shown below:

protected void btnCreate_Click(object sender, EventArgs e)
{
    using (SPLongOperation op = new SPLongOperation(this.Page);
    {
        op.LeadingHTML = "Please wait while XXX completes."}
        op.Begin();
        // do something that takes a fair old while . . .
        op.End("http://somewhere")
    }
}

Basically what happens is you get the nice SharePoint spinny thing (wonder if there's a proper name for this ?!) displayed with your "Please wait while XXX completes" message while the operation is in progress i.e. between the calls to op.Begin() and op.End(). Upon the call to op.End() the browser is then redirected to the URL you pass into the call.

This was working fine for two of my custom application pages (or so I thought) but on a third application page I was having major issues. When I clicked the button on my application page it was taking a good while before the post back occurred and the SharePoint spinny thing appeared. On my other two application pages it was working fine and was redirecting to the SharePoint spinny thing page almost immediately and displaying my waiting message.

I'd never had time to look into why this was, and it was bugging me bug time, but I found some time today. Basically, in the page directive of the application page causing me issues I had the "SmartNavigation" property set to "true". In the other two application pages I didn't. Simple as that (although it took a fair old while to narrow this down, I can assure you !!). I removed the SmartNavigation property from my page directive and it now works as expected.

I'm not sure why the two don't co-exist nicely (perhaps someone can post a comment and tell me) but I'm just pleased to have solved something that has bugged me for so long. Hopefully if you're experiencing delays in waiting for your SharePoint spinny thing in your application page this will help you out !

0 Comments:

Post a Comment

<< Home