Archive

Archive for January, 2012

After “Export to Excel” button click other click/postback events disabled on SharePoint custom webpart

January 16, 2012 6 comments

While working I came across a difficult situation and not able to found the correct reason behind the issue.

I created a custom web part for MOSS2007 with ASP.net grid view control getting date from list using CAML query and display the data in tabular format. Export to excel functionality required to provide the data in excel to be saved locally from the grid view was one of the requirement I implemented using gridview.RenderControl() method.

I implemented the requirement completely and tested it and as expected it is working perfectly. But if we once clicked the “Export to Excel” button after words other control stops responding like sorting on grid view header, pagination stops posting back on click event.

Then started digging into the issue found the details in one of the telerik grid related post.

Issue is the resubmission of form is stopped by SharePoint to prevent the again and again requesting without the previous request completes. SharePoint maintains a JavaScript flag for this which we need to clear to allow the postback to work after Export to excel.

Solution I used is added following script on the custom web part.Other solutions also available for this problem which explained in  telerik grid related post.

<script type="text/javascript" language="javascript">

//sharepoint postback to work after clicking on export to excel button

if (typeof (_spBodyOnLoadFunctionNames) != 'undefined' &&
                                           _spBodyOnLoadFunctionNames != null)
{
_spBodyOnLoadFunctionNames.push("supressSubmitWraper");

}

function supressSubmitWraper() {

_spSuppressFormOnSubmitWrapper = true;

}

</script>
Advertisements