Export (0) Print
Expand All

Button.OnClick Event

Office 2007
Occurs when a button control is clicked within a view in a Microsoft Office InfoPath 2007 form.

Version Information
 Version Added:  InfoPath 2003

Syntax

expression.OnClick(pEvent)

expression   An expression that returns a Button object.

Parameters

NameRequired/OptionalData TypeDescription
pEventRequiredDocActionEventAn event object that is used during a Microsoft Office InfoPath 2007 button click event.

Return Value
nothing

Remarks

This event handler does not allow users to cancel an operation.

Bb229735.vs_note(en-us,office.12).gif  Note
The OnClick event for the InfoPath button control is the only control event that is supported.

Example

In the following example, the OnClick event handler is used to perform data validation on some of the fields contained in the New Customer view when a user clicks a button to switch to another view:

JScript
function btnSwitchContact::OnClick eventObj)
{
   if (XDocument.View.Name == "New Customer")
   {
      if (XDocument.DOM.selectSingleNode
         ('/Customers/CustomerInfo/CustomerName').text == ""
         && XDocument.DOM.selectSingleNode
         ('/Customers/CustomerInfo/CustomerID').text == "")
      {
         XDocument.UI.Alert("The Customer Name and ID must " +
            "be filled in prior to switching the view.");
         return;
      }
      else if (XDocument.DOM.selectSingleNode
         ('/Customers/CustomerInfo/CustomerName').text == "")
      {
         XDocument.UI.Alert("The Customer Name must be filled " +
            "in prior to switching the view.");
         return;
      }
      else if (XDocument.DOM.selectSingleNode
         ('/Customers/CustomerInfo/CustomerID').text == "")
      {
         XDocument.UI.Alert("The Customer ID must be filled in " +
            "prior to switching the view.");
         return;
      }
   }
   XDocument.View.SwitchView('Contact Customer');
}



Community Additions

ADD
Show:
© 2014 Microsoft