Learn how to use SPQuery object to fetch data from a SharePoint list. In one of the previous articles, you saw how one can populate a drop down list box without writing code but now you will see how to do it programmatically. Programming means more power in your hands!
All About SharePoint is a blog about SharePoint, InfoPath and related technologies. It was started in 2005 and has good readership in many countries. It covers SharePoint 2003, 2007, 2010, 2013, 2016 and Office 365. You can read articles, tips, tutorials and news. It has code samples and complete applications as well.
Saturday, July 12, 2008
Wednesday, July 9, 2008
InfoPath: Raising an error on validation
InfoPath provides excellent method to validate controls, for example, you can use data validation alone or in conjuction with Rules to validate data in InfoPath forms. You can also do it programmatically and raise errors which will be shown in the form when there is a validation error. Assume there is a control called FirstName. Here is how you will raise an error on FirstName:
public void FirstName_Changed(object sender, XmlEventArgs e)
{
}
Right click the control and select Programming > Changed Event. Note, Validating Event is also available but we will use Changed Event. Raise any previously raised errors:
this.Errors.Delete("FirstNameError");
After validating, if there is an error, raise it:
this.Errors.Add(Nav, "FirstNameError", "Please add correct value in First Name");
The first parameter is the XPathNavigator object that points to the control.
XPathNavigator nav = this.CreateNavigator().SelectSingleNode(XPath of the firstname field, this.NamespaceManager);
XPath will be like "/my:myFields/my:FirstName".
The second parameter is the name of the error and third parameter is the description of the error.
Happy programming!
Subscribe to:
Posts (Atom)