I have a form that uses a code behind done in C#. The forms contains a
textbox and I am hooking into the onbeforechange event to do some code
validation.
To get the correct source node I am running this code.
private IXMLDOMNode normalizeSource(DataDOMEvent e)
{
if(e.Parent.nodeType == DOMNodeType.NODE_ELEMENT && e.Source.nodeType ==
DOMNodeType.NODE_TEXT)
return e.Parent;
if (e.Source.nodeType == DOMNodeType.NODE_ELEMENT || e.Source.nodeType ==
DOMNodeType.NODE_ATTRIBUTE
return e.Source;
return null;
}
After this I perform some very simple validation which does not pertain the
my question. The odd thing that is happening here is that if the user types
directly into the text box my validation code works as needed. However, if
the user has something copied to the clip board and then paste it into the
text box I keep getting a System.NullReferenceException. Yet I cannot find
the source of my problems.
Anyone have any ideas? Thanks,
-mike
Is there a reason you are going through all of that instead of just using e.Site?
The event object has a Site and Source attribute.
Site = The XML node that the event handler is attached to.
Source = The XML node that caused the change.

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
I have a form that uses a code behind done in C#. The forms contains a
textbox and I am hooking into the onbeforechange event to do some code
validation.
To get the correct source node I am running this code.
private IXMLDOMNode normalizeSource(DataDOMEvent e)
{
if(e.Parent.nodeType == DOMNodeType.NODE_ELEMENT && e.Source.nodeType =DOMNodeType.NODE_TEXT)
return e.Parent;
if (e.Source.nodeType == DOMNodeType.NODE_ELEMENT || e.Source.nodeType =DOMNodeType.NODE_ATTRIBUTE
return e.Source;
return null;
}
After this I perform some very simple validation which does not pertain the
my question. The odd thing that is happening here is that if the user types
directly into the text box my validation code works as needed. However, if
the user has something copied to the clip board and then paste it into the
text box I keep getting a System.NullReferenceException. Yet I cannot find
the source of my problems.
Anyone have any ideas? Thanks,
-mike