2007-03-08
| Rate This Article: | Add This Article To: |
Getting Started
At this point in the book, you not only know how to design form templates that look nice but you can also take advantage of most of the basic (and some not so basic) features available when using InfoPath in design mode. Now you can create professional-looking forms in no time. However, over time, as you create more and more form templates, you may find that many of them are very similar or share a lot of the same constructs.
For example, several of your form templates may contain sections used to collect address information from the user. It would be pretty tedious to have to add the same address block to each of your form templates, especially if there is no difference in this data from one form template to another. You could simply copy the controls and layout from the view and paste them into another form template. This would work fine for the view aspects of the form. However, what about the data structure, rules, calculated default values, data validation, and data connection information that you may have added to your form template? How do you copy these settings from one form template to another? Using copy and paste, this just isn't possible.
There is another way to share different parts of a form template in multiple form templates. With InfoPath 2007, you can build custom components that can be reused in one or more of your form templates. This means that you can create your own components or reuse ones created by third-party software providers.
You can create reusable components in two ways. The first is to write ActiveX controls in C++, Visual Basic, C#, or any COM-aware programming language. Creating controls this way requires you to put on your developer hat and write quite a bit of code. Since this is an advanced topic, we'll talk about this in the advanced section of this book in Chapter 19.
Fortunately, there is a second way to create custom components in InfoPath, one that doesn't require you to write even one line of code. These custom components are called template parts. As their name implies, template parts are parts of a form template. More specifically, template parts group pieces of a form template into a component that can be reused in multiple form templates. These custom components, which include controls, data structure, and many of the design features you've learned about so far (such as rules and data validation), enable you to quickly and easily reuse common design features across as many form templates as you choose. Let's jump right in and see how easy it is to create one of these components.
Designing a New Template Part
Template Part Design Mode
To understand the reason behind this difference, it's important to understand the concept of design targets. Whenever you open InfoPath in design mode, it can have one of two targets--form template or template part--which correspond to the option buttons with the same names in the Design a Form Template dialog. (Of course, in each case, you can specify that the form template or template part is browser-enabled. We will discuss this more in Chapter 14 when we talk about browser forms.) When you are targeting a form template, all the InfoPath design-mode features are available. When you are targeting a template part, only a subset of the design-mode features (those supported by template parts) are available.
For example, a template part can have only one view. So, the Views task pane is not available in the Design Tasks pane (or anywhere else, for that matter). As with the tasks in the Design Tasks pane, the entry points (e.g., menus, dialogs, and so on) for any features that are not available in template parts will be hidden. Table 10.1 lists all the features that are not supported by template parts and, therefore, won't be available in design mode when designing a template part.
Now that you've opened InfoPath in design mode to design a template part, the experience should be very familiar since you've designed a form template before. So, let's create our address block component. As we mentioned, the address block we want to create is the same one used in the MOI employment application form. So, to make things a little easier, let's just copy all the controls and layout from the view in the employment application form and paste them into the view of the template part we are creating. To do this, open the employment application form we created back in Chapter 2 (which is available with the samples for Chapter 2 on the book's Web site), select the Address Section control by clicking the design-time visual tab for the Section control and then press Ctrl+C to copy it. Then go to the template part and paste the controls and layout into the view for the template part.
Once you've changed the bindings for each of the controls, you have a fully functional template part that you can use in any form template. But before you can reuse this component in other form templates, you have to save it. In terms of what you do, saving a template part is no different than saving a form template. However, when you save, InfoPath will give the template part the .xtp extension instead of the .xsn extension used for form templates. This will be important later when you try to locate template parts to reuse. When you save the template part, the name you give the file will be the name you'll use when you install the template part into your Controls task pane, which we'll show you how to do next.
You've created your first template part, so let's put it to use. (In the last chapter, you learned about publishing form templates. You don't actually publish template parts as you do form templates. Saving a template part is analogous to publishing it in this case.)
Discuss Designing Forms for Microsoft Office InfoPath and Forms Services 2007 (Part 1) >>> Be the FIRST to comment on this article!

>>> More Microsoft Architecture Articles >>> More By DevSource

