XDocument.OnContextChange Event

InfoPath Developer Reference

Occurs after the context node changes.

Version Information
 Version Added:  InfoPath 2003

Syntax

expression.OnContextChange(pEvent)

expression   An expression that returns a XDocument object.

Parameters

Name Required/Optional Data Type Description
pEvent Required DocContextChangeEvent An event object that is used during a Microsoft Office InfoPath 2007 context change event.

Return Value
nothing

Remarks

The context node is the XML DOM node mapped to the view that corresponds to the container (or item) with the current XML selection. For example, if the current selection in the view is in a text box, the context node is the node to which the text box is bound. If the current selection is a repeating section, the context node is the node for that item. If two repeating sections are selected, the context node is the ancestor XML DOM for both items mapped to the view.

The OnContextChange event is asynchronous. It does not fire on every change in the context node; instead, it fires after the application has stopped processing other events.

When the document loads, or when a view change occurs, the OnContextChange event will occur after the OnLoad and OnSwitchView events occur.

When the IsUndoRedo property of the DocContextChangeEvent object is True, the context change was caused by a user's undo or redo operation rather than an explicit user context change. Operations performed within the OnContextChange event handler that modify the XML DOM should be avoided in response to undo or redo operations, because they may interfere with the user's intention to revert data to a previous state.

For rich text box controls, the OnContextChange event is not raised for context changes within the XHTML content—that is, selection changes to the rich text in the control. The GetContextNodes method can be used to determine the selection within rich text box controls.

Example

In the following example, instructions specific to different context nodes in a form are added to the body of a custom task pane. A custom HTML task pane should be added to the form template in design mode:

JScript
  function XDocument::OnContextChange(eventObj) 
{
    var oContextNode = eventObj.Context;
var strText = "";
if( oContextNode.nodeName == "my:root" )
    strText = "";
else if( oContextNode.nodeName == "my:singleName" )
    strText = "Type your full name.";
else if( oContextNode.nodeName == "my:webSite" )
    strText = "Type the Web address of your personal web page.";

var oTaskPane = XDocument.View.Window.TaskPanes.Item(0);
oTaskPane.HTMLDocument.body.innerText = strText;

}

See Also