Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / September 2004

Tip: Looking for answers? Try searching our database.

System.NullReferenceException

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Morse - 17 Sep 2004 19:43 GMT
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
Greg Collins [MVP] - 18 Sep 2004 16:46 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.