XmlValidatingEventArgs.ReportError Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ReportError(XPathNavigator, Boolean, String) |
Creates a FormError object that contains custom error information with the specified values and adds it to the FormErrorCollection object of the form. |
ReportError(XPathNavigator, Boolean, String, String) |
Creates a FormError object that contains custom error information with the specified values and adds it to the FormErrorCollection object of the form. |
ReportError(XPathNavigator, Boolean, String, String, Int32) |
Creates a FormError object that contains custom error information with the specified values and adds it to the FormErrorCollection object of the form. |
ReportError(XPathNavigator, Boolean, String, String, Int32, ErrorMode) |
Creates a FormError object that contains custom error information with the specified values and adds it to the FormErrorCollection object of the form. |
ReportError(XPathNavigator, Boolean, String)
Creates a FormError object that contains custom error information with the specified values and adds it to the FormErrorCollection object of the form.
public:
abstract void ReportError(System::Xml::XPath::XPathNavigator ^ node, bool siteIndependent, System::String ^ message);
public abstract void ReportError (System.Xml.XPath.XPathNavigator node, bool siteIndependent, string message);
abstract member ReportError : System.Xml.XPath.XPathNavigator * bool * string -> unit
Public MustOverride Sub ReportError (node As XPathNavigator, siteIndependent As Boolean, message As String)
Parameters
- node
- XPathNavigator
An XPathNavigator positioned at the node that contains the data the error is associated with.
- siteIndependent
- Boolean
Sets the condition for automatic deletion of the FormError object. If set to true, the FormError object will be deleted for changes to any nodes that match the XPath expression returned by the Match property of this event object. If set to false, the FormError object is deleted the next time the form is validated only when the node returned by the Site property of this event object has been changed.
- message
- String
The text to be used for the short error message.
Exceptions
The parameters passed to this method are not valid.
The parameters passed to this method are a null reference (Nothing in Visual Basic).
Examples
In the following example, the Site property that the XmlValidatingEventArgs class inherits from the XmlEventArgs class is used to check the value of the node that raised the Validating event. If the data validation fails, the ReportError method is used to create a custom error.
public void field1_Validating(object sender, XmlValidatingEventArgs e)
{
if (e.Site.InnerXml != String.Empty)
{
int fieldValue = int.Parse((e.Site.InnerXml));
if (fieldValue > 50)
{
e.ReportError(e.Site,
false,
"Quantity cannot exceed 50.");
}
if (fieldValue < 0)
{
e.ReportError(e.Site,
false,
"Quantity cannot be less than 0.");
}
}
}
Public Sub field1_Validating(ByVal sender As Object , _
ByVal e As XmlValidatingEventArgs)
If (e.Site.InnerXml <> String.Empty) Then
Integer fieldValue = Integer.Parse((e.Site.InnerXml))
If (fieldValue > 50) Then
e.ReportError(e.Site,
false,
"Quantity cannot exceed 50.")
End If
If (fieldValue < 0) Then
e.ReportError(e.Site,
false,
"Quantity cannot be less than 0.")
End If
End If
End Sub
Remarks
The ReportError method is used to create a custom error for an error that occurred during the Validating event.
When the ReportError method is called, InfoPath creates a FormError object and adds it to the FormErrorCollection of the current form. FormError objects are removed from the collection when the validation constraint is no longer invalid. In certain cases they can be explicitly removed using the Delete(FormError) or DeleteAll() methods.
FormError objects can also be created using the Add(XPathNavigator, String, String, String) method of the FormErrorCollection class.
Note: Site-independent errors should be used when you want the errors to apply to all nodes of the same type. If you want the error to apply to a specific node, use site-dependent errors.
This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.
This type or member can be accessed from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.
Applies to
ReportError(XPathNavigator, Boolean, String, String)
Creates a FormError object that contains custom error information with the specified values and adds it to the FormErrorCollection object of the form.
public:
abstract void ReportError(System::Xml::XPath::XPathNavigator ^ node, bool siteIndependent, System::String ^ message, System::String ^ messageDetails);
public abstract void ReportError (System.Xml.XPath.XPathNavigator node, bool siteIndependent, string message, string messageDetails);
abstract member ReportError : System.Xml.XPath.XPathNavigator * bool * string * string -> unit
Public MustOverride Sub ReportError (node As XPathNavigator, siteIndependent As Boolean, message As String, messageDetails As String)
Parameters
- node
- XPathNavigator
An XPathNavigator positioned at the node that contains the data the error is associated with.
- siteIndependent
- Boolean
Sets the condition for automatic deletion of the FormError object. If set to true, the FormError object will be deleted for changes to any nodes that match the XPath expression returned by the Match property of this event object. If set to false, the FormError object is deleted the next time the form is validated only when the node returned by the Site property of this event object has been changed.
- message
- String
The text to be used for the short error message.
- messageDetails
- String
The text to be used for the detailed error message.
Exceptions
The parameters passed to this method are not valid.
The parameters passed to this method are a null reference (Nothing in Visual Basic).
Examples
In the following example, the Site property that the XmlValidatingEventArgs class inherits from the XmlEventArgs class is used to check the value of the node that raised the Validating event. If the data validation fails, the ReportError method is used to create a custom error.
public void field1_Validating(object sender, XmlValidatingEventArgs e)
{
if (e.Site.InnerXml != String.Empty)
{
int fieldValue = int.Parse((e.Site.InnerXml));
if (fieldValue > 50)
{
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot exceed 50.");
}
if (fieldValue < 0)
{
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot be less than 0.");
}
}
}
Public Sub field1_Validating(ByVal sender As Object , _
ByVal e As XmlValidatingEventArgs)
If (e.Site.InnerXml <> String.Empty) Then
Integer fieldValue = Integer.Parse((e.Site.InnerXml))
If (fieldValue > 50) Then
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot exceed 50.")
End If
If (fieldValue < 0) Then
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot be less than 0.")
End If
End If
End Sub
Remarks
The ReportError method is used to create a custom error for an error that occurred during the Validating event.
When the ReportError method is called, InfoPath creates a FormError object and adds it to the FormErrorCollection of the current form. FormError objects are removed from the collection when the validation constraint is no longer invalid. In certain cases they can be explicitly removed using the Delete(FormError) or DeleteAll() methods.
FormError objects can also be created using the Add(XPathNavigator, String, String, String) method of the FormErrorCollection class.
Note: Site-independent errors should be used when you want the errors to apply to all nodes of the same type. If you want the error to apply to a specific node, use site-dependent errors.
This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.
This type or member can be accessed from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.
Applies to
ReportError(XPathNavigator, Boolean, String, String, Int32)
Creates a FormError object that contains custom error information with the specified values and adds it to the FormErrorCollection object of the form.
public:
abstract void ReportError(System::Xml::XPath::XPathNavigator ^ node, bool siteIndependent, System::String ^ message, System::String ^ messageDetails, int errorCode);
public abstract void ReportError (System.Xml.XPath.XPathNavigator node, bool siteIndependent, string message, string messageDetails, int errorCode);
abstract member ReportError : System.Xml.XPath.XPathNavigator * bool * string * string * int -> unit
Public MustOverride Sub ReportError (node As XPathNavigator, siteIndependent As Boolean, message As String, messageDetails As String, errorCode As Integer)
Parameters
- node
- XPathNavigator
An XPathNavigator positioned at the node that contains the data the error is associated with.
- siteIndependent
- Boolean
Sets the condition for automatic deletion of the FormError object. If set to true, the FormError object will be deleted for changes to any nodes that match the XPath expression returned by the Match property of this event object. If set to false, the FormError object is deleted the next time the form is validated only when the node returned by the Site property of this event object has been changed.
- message
- String
The text to be used for the short error message.
- messageDetails
- String
The text to be used for the detailed error message.
- errorCode
- Int32
The number to be used as the error code.
Exceptions
The parameters passed to this method are not valid.
The parameters passed to this method are a null reference (Nothing in Visual Basic).
Examples
In the following example, the Site property that the XmlValidatingEventArgs class inherits from the XmlEventArgs class is used to check the value of the node that raised the Validating event. If the data validation fails, the ReportError method is used to create a custom error.
public void field1_Validating(object sender, XmlValidatingEventArgs e)
{
if (e.Site.InnerXml != String.Empty)
{
int fieldValue = int.Parse((e.Site.InnerXml));
if (fieldValue > 50)
{
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot exceed 50.",
12345);
}
if (fieldValue < 0)
{
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot be less than 0.",
12346);
}
}
}
Public Sub field1_Validating(ByVal sender As Object , _
ByVal e As XmlValidatingEventArgs)
If (e.Site.InnerXml <> String.Empty) Then
Integer fieldValue = Integer.Parse((e.Site.InnerXml))
If (fieldValue > 50) Then
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot exceed 50.",
12345)
End If
If (fieldValue < 0) Then
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot be less than 0.",
12346)
End If
End If
End Sub
Remarks
The ReportError method is used to create a custom error for an error that occurred during the Validating event.
When the ReportError method is called, InfoPath creates a FormError object and adds it to the FormErrorCollection of the current form. FormError objects are removed from the collection when the validation constraint is no longer invalid. In certain cases they can be explicitly removed using the Delete(FormError) or DeleteAll() methods.
FormError objects can also be created using the Add(XPathNavigator, String, String, String) method of the FormErrorCollection class.
Note: Site-independent errors should be used when you want the errors to apply to all nodes of the same type. If you want the error to apply to a specific node, use site-dependent errors.
This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.
This type or member can be accessed from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.
Applies to
ReportError(XPathNavigator, Boolean, String, String, Int32, ErrorMode)
Creates a FormError object that contains custom error information with the specified values and adds it to the FormErrorCollection object of the form.
public:
abstract void ReportError(System::Xml::XPath::XPathNavigator ^ node, bool siteIndependent, System::String ^ message, System::String ^ messageDetails, int errorCode, Microsoft::Office::InfoPath::ErrorMode errorMode);
public abstract void ReportError (System.Xml.XPath.XPathNavigator node, bool siteIndependent, string message, string messageDetails, int errorCode, Microsoft.Office.InfoPath.ErrorMode errorMode);
abstract member ReportError : System.Xml.XPath.XPathNavigator * bool * string * string * int * Microsoft.Office.InfoPath.ErrorMode -> unit
Parameters
- node
- XPathNavigator
An XPathNavigator positioned at the node that contains the data the error is associated with.
- siteIndependent
- Boolean
Sets the condition for automatic deletion of the FormError object. If set to true, the FormError object will be deleted for changes to any nodes that match the XPath expression returned by the Match property of this event object. If set to false, the FormError object is deleted the next time the form is validated only when the node returned by the Site property of this event object has been changed.
- message
- String
The text to be used for the short error message.
- messageDetails
- String
The text to be used for the detailed error message.
- errorCode
- Int32
The number to be used as the error code.
- errorMode
- ErrorMode
An ErrorMode that specifies whether the error will be displayed in a modal dialog box, or modelessly with a wavy underline in the affected control.
Exceptions
The parameters passed to this method are not valid.
The parameters passed to this method are a null reference (Nothing in Visual Basic).
Examples
In the following example, the Site property that the XmlValidatingEventArgs class inherits from the XmlEventArgs class is used to check the value of the node that raised the Validating event. If the data validation fails, the ReportError method is used to create a custom error.
public void field1_Validating(object sender, XmlValidatingEventArgs e)
{
if (e.Site.InnerXml != String.Empty)
{
int fieldValue = int.Parse((e.Site.InnerXml));
if (fieldValue > 50)
{
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot exceed 50.",
12345,
ErrorMode.Modeless);
}
if (fieldValue < 0)
{
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot be less than 0.",
12346,
ErrorMode.Modeless);
}
}
}
Public Sub field1_Validating(ByVal sender As Object , _
ByVal e As XmlValidatingEventArgs)
If (e.Site.InnerXml <> String.Empty) Then
Integer fieldValue = Integer.Parse((e.Site.InnerXml))
If (fieldValue > 50) Then
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot exceed 50.",
12345,
ErrorMode.Modeless)
End If
If (fieldValue < 0) Then
e.ReportError(e.Site,
false,
"Invalid quantity",
"The total number cannot be less than 0.",
12346,
ErrorMode.Modeless)
End If
End If
End Sub
Remarks
The ReportError method is used to create a custom error for an error that occurred during the Validating event.
When the ReportError method is called, InfoPath creates a FormError object and adds it to the FormErrorCollection of the current form. FormError objects are removed from the collection when the validation constraint is no longer invalid. In certain cases they can be explicitly removed using the Delete(FormError) or DeleteAll() methods.
FormError objects can also be created using the Add(XPathNavigator, String, String, String) method of the FormErrorCollection class.
Note: Site-independent errors should be used when you want the errors to apply to all nodes of the same type. If you want the error to apply to a specific node, use site-dependent errors.
This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.
This type or member can be accessed only from code running in forms opened in Microsoft InfoPath Filler.