Skip to content

Instantly share code, notes, and snippets.

@emiliano-poggi
Last active August 29, 2015 14:15
Show Gist options
  • Save emiliano-poggi/5b4893f6f6add87ae2ee to your computer and use it in GitHub Desktop.
Save emiliano-poggi/5b4893f6f6add87ae2ee to your computer and use it in GitHub Desktop.
SharePoint 2013 Visual Studio Team Foundation Web Parts How To Automatically Refresh Query Results Without Postback Action

SharePoint 2013 Visual Studio Team Foundation Web Parts How To Automatically Refresh Query Results Without Postback Action

You want to refresh the Query Results web parts of Visual Studio Team Foundtion embedded into a web part page, so that every 3 seconds the user has a query updated without having to refresh the entire page. Obviously you want automatically refresh the single web part, not the entire web page.

  1. In Edit mode, search in the web page runtime elements for the keyword "Refresh Results". You should find one or more ie:menuitem elements, many elements as many Query Results web parts you have. See the snippet_menuitem.html below for an example.
  2. The script you are interested to is in the onmenuclick attribute.
  3. After you have taken note of all required onmenuclick values just build you refresher as shown below.
/* refresh function for a TFS web part */
function refreshTFSWP() {
_ctl00_ctl40_g_316d0ee0_9865_421e_a184_cee73003868a_ctl00.refresh(true);
return false;
}
<!-- this code has been found on the SharePoint page runtime elements
and shows the call we must perform for refreshing the web part in the
onmenuclick attribute -->
<ie:menuitem
id="partverb_1_ctl00_ctl40_g_316d0ee0_9865_421e_a184_cee73003868aRefresh_WebPartctl00_ctl40_g_316d0ee0_9865_421e_a184_cee73003868a"
iconsrc="/swfactory/teamsite/_layouts/tswa/Resources/Images/refresh.gif"
onmenuclick="_ctl00_ctl40_g_316d0ee0_9865_421e_a184_cee73003868a_ctl00.refresh(false);return false;"
text="Refresh Results" type="option" unselectable="on"></ie:menuitem>
<!-- refresh every 3 seconds -->
<script type="text/javascript">
$(document).ready( function() {
setInterval(refreshTFSWP, 3000);
} );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment