Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value

Gets the user context.

var value = Ewa.AsyncResult.getUserContext();

Return Value



The [AsyncResult.getUserContext] method returns the same value that was passed into the asynchronous method call. As an example, consider the [Workbook.getRangeA1Async(addressA1,callback,userContext)] method where userContext is passed in as the last argument to the method call. The [userContext] parameter is provided as a way for callers to pass state through the asynchronous call. All asynchronous methods in the JavaScript object model for Excel Services in Microsoft SharePoint Server 2010 have the [userContext] parameter as the last parameter in their signatures.


A null can be passed as the argument for the userContext parameter.


The following code example adds a button and a text input box to the page and then adds code to the button onClick event that takes the range address entered into the text box (in A1 notation) and activates the specified range. The code uses the AsyncResult.getUserContext method to get the user state passed in to the callback method.

<script type="text/javascript">
var ewa = null;
// Add event handler for onload event.
if (window.attachEvent) 
    window.attachEvent("onload", ewaOmPageLoad);    
    window.addEventListener("DOMContentLoaded", ewaOmPageLoad, false); 

// Add event handler for applicationReady event.
function ewaOmPageLoad() 

function getEwa()
    // Get a reference to the Excel Services Web Part.
    ewa = Ewa.EwaControl.getInstances().getItem(0);                                       

function getRangeA1Button()
    // Get the A1 address entered.
    var a1Address = document.forms.aspnetForm.GetRangeAddress.value;
    // Call getRangeA1Async with the A1 address entered.
    ewa.getActiveWorkbook().getActiveSheet().getRangeA1Async(a1Address, getRangeA1Callback, null);    

function getRangeA1Callback(asyncResult)
    // getRangeA1Async returns a range object through the AsyncResult object
    var range = asyncResult.getReturnValue();
    // Activate the range that the user entered.
    // Pass in range as user context so it can be used in callback.

function activateAsyncCallback(asyncResult)
    // activateAsync does not return a range through AsyncResult, so 
    // get the range from the user context passed in with activateAsync call.
    var range = asyncResult.getUserContext();
    // Display which address for which range was activated.
    window.status = "Range located at A1 address: " + range.getAddressA1() + " was activated.";

<input type="button" id="GetRange" VALUE="Get Range" onclick="getRangeA1Button()">
<input type="text" id="GetRangeAddress" value="Enter A1 Address">

See Also


Ewa.AsyncResult Methods


Ewa Namespace