Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ScriptObject.Invoke Method

Silverlight

Invokes a method on the current scriptable object, and optionally passes in one or more method parameters.

Namespace:  System.Windows.Browser
Assembly:  System.Windows.Browser (in System.Windows.Browser.dll)
public virtual Object Invoke(
	string name,
	params Object[] args
)

Parameters

name
Type: System.String
The method to invoke.
args
Type: System.Object[]
Parameters to be passed to the method.

Return Value

Type: System.Object
An object that represents the return value from the underlying JavaScript method.
ExceptionCondition
ArgumentNullException

name is null.

ArgumentException

name is an empty string.

-or-

name contains an embedded null character (\0).

-or-

The method does not exist or is not scriptable.

InvalidOperationException

The underlying method invocation results in an error. The .NET Framework attempts to return the error text that is associated with the error.

Return values follow the rules for returning types from JavaScript to managed code using by-reference marshaling rules. For more information, see Returning or Passing Managed Types to JavaScript.

The possible types for args follow the rules for passing managed types to JavaScript using by-reference marshaling rules.

If args is null, it is interpreted as an empty parameter list. As a result, passing null is the same as passing new object[].

The actual type of the return value is always a string, a primitive type, or a ScriptObject reference. If the underlying value of the requested property is a managed type (other than a derivation of ScriptObject), you can use the ManagedObject property to get the underlying managed type reference.

The following example shows how you can access individual items in a ScriptObject that contains either a JavaScript collection or a dictionary by invoking the item property (ordinal for arrays, and key for dictionary) and passing an ordinal for a parameter.

// Fetch the sixth item in a collection.
Invoke("item",5);
// Fetch address item from dictionary.
Invoke("item","address"); 

However, this approach will not work for simple JavaScript arrays. For information about how to access an item in a simple JavaScript array, see ScriptObject.GetProperty.

Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.