This article will show you how to create and edit an HTML Web Part in SharePoint 2010. The Web Part gives you the ability to format a section of the SharePoint site in any way that you want.



Overview

You can use the HTML Form Web Part to connect and pass data to another Web Part. For example, you can use the default HTML Form Web Part to type a region name, pass the value to a List View Web Part of customer data, and filter the data by that region. You can also customize the HTML Form Web Part to enable a user to, for example, select the region name from a drop-down list. You can use text boxes, drop-down lists, multi-line text boxes, check boxes, or option buttons in the HTML Form Web Part.

The way you connect fields to the other Web Part depends on how the other Web Part has been defined to use Web Part connections.

Although you can have more than one element (text box, radio buttons, and so on) on your form, only one field can be connected to a List View Web Part. However, different fields can be connected to different Web Parts at the same time. For example, you can have an HTML Form Web Part with a text box and a set of option buttons. The text box can be connected to one List View Web Part and the option buttons to another. When the user clicks the Go button, both List View Web Parts are filtered according to the information entered on the HTML Form Web Part.

You can connect two or more fields in the HTML Form Web Part to another Web Part, if that Web Part can accept multiple parameters. In this case, you may need a SharePoint-compatible Web design program, such as SharePoint Designer 2010 to complete the connections.

Add a Web Part to a page

To edit a page you must have at least the permissions obtained by being added to the default <Site Name> Members SharePoint group for the site.

  1. From a page, in the ribbon, click the Page tab, and then click the Edit command.

Edit command of the Page tab

 Note    If the Edit command is disabled, you may not have the permissions to edit the page. Contact your administrator.

  1. Click on the page where you want to add a Web Part, click the Insert tab, and then click Web Part.

Web Part command

  1. Under Categories, select a category, such as Lists and Libraries, select the Web Part that you want to add to the page, such as Announcements, and then click Add.

Web Part picker

  1. When you select a Web Part, information about the Web Part is displayed in About the Web Part.
  2. When you have finished editing the page, click the Page tab, and then click Save & Close.

Connect the HTML Form Web Part to another Web Part

To use the HTML Form Web Part, you connect it with another Web Part that is capable of receiving values through a Web Part connection, such as the List View Web Part. The list you want to filter, and the column on which you want to filter it, must be visible in a Web Part on the same page as the HTML Form Web Part. For information about adding an HTML Form Web Part to a page, see Add a Web Part to a Page.

  1. Browse to the page containing the Web Part you want to filter.
  2. In the ribbon, click the Page tab, and then click the Edit command.

 Note:    If the Edit command is disabled, you may not have the permissions to edit the page. Contact your administrator.

  1. Point to the HTML Form Web Part, click the down arrow, click Connections, point to Provide Form Value To, and then click the name of the Web Part to which you want to link.
  2. In the Choose Connection dialog box, click the Configure Connection tab.
  3. From the Connection Type menu, select the field that matches the information from the HTML Form Web Part.

 Note:    The fields do not have to have the same names, nor do they have to be the same data types. The values sent from the HTML Form Web Part are text values.

  1. Click Finish, and then click Exit Edit Mode at the top of the page.

By default, you can enter text in the text box and then click Go or press ENTER. The other Web Part will display only the data that matches the text you entered. To clear the text box so that you can enter new text, select the current text, and then delete it.

Customize the HTML Form Web Part

You can customize the HTML Form Web Part by using either the Source Editor, which is available from the HTML Form Web Part tool pane, or a SharePoint-compatible Web design program, such as SharePoint Designer 2010. Instead of the standard text box, you can use option buttons, check boxes, multi-line text boxes, and list boxes. You can also add labels and assign a default value.

If you customize the HTML Form Web Part, keep in mind the following:

  • Only one Go button (which uses the INPUT element) can be used to pass data to another Web Part.
  • The HTML Form Web Part uses the FORM element. Certain HTML elements cannot be used inside the FORM element, including the HTML, BODY, and FORM elements.
  • All form field names must be unique. Each name value is used to connect to a corresponding column name in the Web Part that you are connecting to.

To customize the Form Web Part, use the Source Editor button to display the Text Editor dialog box and then revise or add the HTML source code.

 Note    The HTML Form Web Part only provides data to another connectable Web Part — it cannot get data from another connectable Web Part. For example, you cannot use the HTML Form Web Part as a detail form to display a row of data.

Customize the default HTML Form Web Part

To customize the default HTML Form Web Part, do the following:

  1. From the page displaying the HTML Form Web Part, in the Ribbon, click the Edit tab, and then click the Edit command.
  2. Point to the HTML Form Web Part, click the down arrow, and then click Edit Web Part.
  3. On the tool pane, click the Source Editor button.
  4. The Text Entry dialog box opens with the default HTML code.

To make the code easier to read and modify, insert carriage returns in the text to break the lines as shown here:

<div onkeydown="javascript:if (event.keyCode == 13) _SFSUBMIT_">
<input type="text" name="T1"/>
<input type="button" value="Go" onclick="javascript:_SFSUBMIT_"/>
</div>

 

You can change the first INPUT element in several ways by changing the name of a field, adding a label to a field, or adding a default value.

Property Description
Field name The name of the default text box in the Form Web Part is T1. This is the name that appears in the Configuration Connection dialog box. To give the field a more meaningful name, type a new name in place of T1. Do not remove the quotation marks.
Field label

You can add label text before or after the form field. Type the text without quotations marks.

default value You can add a default value to the text area field. The user can accept the value by clicking the Go button, or override it by typing their own entry. To add a default value, use the value attribute.

For example if you want to provide a more meaningful name, add a default value, and add a label, you can do the following:

Region: <input type="text" name="Region" value="India"/>

 

You can change the second INPUT element by changing the name of the button, as the following example shows:

<input type="button" value="SUBMIT" onclick="javascript:_SFSUBMIT_"/>

 

You can also add other HTML elements before and after the DIV element. For example, a very useful and simple way to enable the user to quickly refresh the page and reset the FORM elements is to add an anchor tag of the current page after the closing DIV element. For example:

<br/>
<a href="http://contoso/SitePages/CustByRegion.aspx">Refresh</a>

 Important    Do not change the other HTML code in the Text Editor dialog box. The HTML Form Web Part dynamically creates a scripting routine at run time to create the connection to the other Web Part. Do not modify the onkeydown or onclick event code, or you may unintentionally break the HTML Form Web Part.

Use a multi-line text box

The TEXTAREA element defines a multi-line text input control. The ROWS attribute specifies the number of lines that are visible in the text field. The COLS attribute specifies the width of the text area in characters. In the following example, the user sees a text box of 5 lines and 30 characters in width. When the user enters text in the box, the text will wrap at 30 characters.

<textarea name="Region" rows=5 cols=30></textarea>

 Tip    Make sure there is no space in the source code immediately after the right angle bracket (>).

Use option buttons

Option buttons, also called radio buttons, provide mutually exclusive choices to a user. The following example displays three radio buttons. Use the same name for each radio button. It’s customary to add the labels after each button. If you want to format each radio button on a separate line, use the BR element.

<input type="radio" name="Region" value="India"/> India<BR/>
<input type="radio" name="Region" value="USA"/> USA<BR/>
<input type="radio" name="Region" value="Spain"/> Spain<BR/>

Use a drop-down list of choices

If there are many mutually exclusive choices, consider using a drop down list box by using the SELECT element. Each option appears as a separate choice in the list, but the user can only select one choice. The text after the closing angle bracket of the OPTION element is what appears in the drop-down list.

<select name="Region">
<option value="India">India</option>
<option value="USA">USA</option>
<option value="Spain"> Spain </option>
</select>

 

To provide a default value, such as Spain, do the following:

<option value="Spain" selected="selected"> Spain </option>

 

Use checkboxes

If there are several non-mutually exclusive choices, consider using checkboxes. Each option appears as a separate check box, and the user can select any or all choices. Using this option requires a Web Part that accepts multiple parameters as part of the Web Part connection.

<input type="checkbox" name="region1" value="India"/> India<BR/>
<input type="checkbox" name="region2" value="USA"/> USA<BR/>
<input type="checkbox" name="region3" value="Spain"/> Spain<BR/>

 

To provide a default value, such as Spain, do the following:

<input type="checkbox" name="region3" value="Spain" checked="checked"/> Spain<BR/>

 

Configure the common properties of a Web Part

Web parts share a common set of properties that control their appearance, layout, and advanced characteristics. You change Web Part properties in the tool pane.

 Note    The common Web Part properties that you see in the tool pane may be different from what is documented in this section for several reasons:

  • To see the Advanced section in the tool pane, you must have appropriate permission.
  • For a specific Web Part, a Web Part developer may have chosen not to display one or more of these common properties or may have chosen to create and display additional properties that are not listed below in the Appearance, Layout, and Advanced sections of the tool pane.
  • Some permission and property settings may disable or hide Web Part properties.

Appearance

Property Description
Title Specifies the title of the Web Part that appears in the Web Part title bar.
Height Specifies the height of the Web Part.
Width Specifies the width of the Web Part.
Chrome State Specifies whether the entire Web Part appears on the page when a user opens the page. By default, the chrome state is set to Normal and the entire Web Part appears. Only the title bar appears when the state is set to Minimized.
Chrome Type Specifies whether the title bar and border of the Web Part frame are displayed.

Layout

Property Description
Hidden

Specifies whether the Web Part is visible when a user opens the page. If the check box is selected, the Web Part is visible only when you are designing the page and has the suffix (Hidden) appended to the title.

You can hide a Web Part if you want to use it to provide data to another Web Part through a Web Part connection, but you do not want to display the Web Part.

Direction Specifies the direction of the text in the Web Part content. For example, Arabic is a right-to-left language; English and most other European languages are left-to-right languages. This setting may not be available for all types of Web Parts.
Zone

Specifies the zone on the page where the Web Part is located.

 Note    Zones on the page are not listed in the list box when you do not have permission to modify the zone.

Zone Index

Specifies the position of the Web Part in a zone when the zone contains more than one Web Part.

To specify the order, type a positive integer in the text box.

If the Web Parts in the zone are ordered from top to bottom, a value of 1 means that the Web Part appears at the top of the zone. If the Web Parts in the zone are ordered from left to right, a value of 1 means that the Web Part appears on the left of the zone.

For example, when you add a Web Part to an empty zone that is ordered from top to bottom, the Zone Index is 0. When you add a second Web Part to the bottom of the zone, its Zone Index is 1. To move the second Web Part to the top of the zone, type 0, and then type 1 for the first Web Part.

 Note    Each Web Part in the zone must have a unique Zone Index value. Therefore, changing the Zone Index value for the current Web Part can also change the Zone Index value for other Web Parts in the zone.

Advanced

Property Description
Allow Minimize Specifies whether the Web Part can be minimized.
Allow Close Specifies whether the Web Part can be removed from the page.
Allow Hide Specifies whether the Web Part can be hidden.
Allow Zone Change Specifies whether the Web Part can be moved to a different zone.
Allow Connections Specifies whether the Web Part can participate in connections with other Web Parts.
Allow Editing in Personal View Specifies whether the Web Part properties can be modified in a personal view.
Export Mode Specifies the level of data that is permitted to be exported for this Web Part. Depending on your configuration, this setting may not be available.
Title URL Specifies the URL of a file containing additional information about the Web Part. The file is displayed in a separate browser window when you click the Web Part title.
Description Specifies the ScreenTip that appears when you rest the mouse pointer on the Web Part title or Web Part icon. The value of this property is used when you search for Web Parts by using the Search command on the Find Web Parts menu of the tool pane.
Help URL Specifies the location of a file containing Help information about the Web Part. The Help information is displayed in a separate browser window when you click the Help command on the Web Part menu.
Help Mode

Specifies how a browser will display Help content for a Web Part.

Select one of the following:

Modal Opens a separate browser window, if the browser has this capability. A user must close the window before returning to the Web page.

Modeless Opens a separate browser window, if the browser has this capability. A user does not have to close the window before returning to the Web page. This is the default value.

Navigate Opens the Web page in the current browser window.

 Note    Even though custom Microsoft ASP.NET Web Parts support this property, default SharePoint Help topics open only in a separate browser window.

Catalog Icon Image URL Specifies the location of a file containing an image to be used as the Web Part icon in the Web Part List. The image size must be 16 by 16 pixels.
Title Icon Image URL Specifies the location of a file containing an image to be used in the Web Part title bar. The image size must be 16 by 16 pixels.
Import Error Message Specifies a message that appears if there is a problem importing the Web Part.

 

Common properties of Web Parts

All Web Parts share a common set of properties that control their appearance, layout, and advanced characteristics.

 Note   The common Web Part properties that you see in the tool pane may be different from what is documented in this section for several reasons:

  • To see the Advanced section in the tool pane, you must have appropriate permission.
  • For a specific Web Part, a Web Part developer may have chosen not to display one or more of these common properties or may have chosen to create and display additional properties that are not listed below in the Appearance, Layout, and Advanced sections of the tool pane.
  • Some permission and property settings may disable or hide Web Part properties.

 

Appearance

Property Description
Title Specifies the title of the Web Part that appears in the Web Part title bar.
Height Specifies the height of the Web Part.
Width Specifies the width of the Web Part.
Chrome State Specifies whether the entire Web Part appears on the page when a user opens the Web Part Page. By default, the chrome state is set to Normal and the entire Web Part appears. Only the title bar appears when the state is set to Minimized.
Chrome Type Specifies whether the title bar and border of the Web Part frame are displayed.

 

Layout

Property Description
Hidden

Specifies whether the Web Part is visible when a user opens the Web Part Page. If the check box is selected, the Web Part is visible only when you are designing the page and has the suffix (Hidden) appended to the title.

You can hide a Web Part if you want to use it to provide data to another Web Part through a Web Part connection, but you don't want to display the Web Part.

Direction Specifies the direction of the text in the Web Part content. For example, Arabic is a right-to-left language; English and most other European languages are left-to-right languages. This setting may not be available for all types of Web Parts.
Zone

Specifies the zone on the Web Part Page where the Web Part is located.

 Note   Zones on the Web Part Page are not listed in the list box when you do not have permission to modify the zone.

Zone Index

Specifies the position of the Web Part in a zone when the zone contains more than one Web Part.

To specify the order, type a positive integer in the text box.

If the Web Parts in the zone are ordered from top to bottom, a value of 1 means that the Web Part appears at the top of the zone. If the Web Parts in the zone are ordered from left to right, a value of 1 means that the Web Part appears on the left of the zone.

For example, when you add a Web Part to an empty zone that is ordered from top to bottom, the Zone Index is 0. When you add a second Web Part to the bottom of the zone, its Zone Index is 1. To move the second Web Part to the top of the zone, type 0, and then type 1 for the first Web Part.

 Note   Each Web Part in the zone must have a unique Zone Index value. Therefore, changing the Zone Index value for the current Web Part can also change the Zone Index value for other Web Parts in the zone.

Advanced

Property Description
Allow Minimize Specifies whether the Web Part can be minimized.
Allow Close Specifies whether the Web Part can be removed from the Web Part Page.
Allow Hide Specifies whether the Web Part can be hidden.
Allow Zone Change Specifies whether the Web Part can be moved to a different zone.
Allow Connections Specifies whether the Web Part can participate in connections with other Web Parts.
Allow Editing in Personal View Specifies whether the Web Part properties can be modified in a personal view.
Export Mode Specifies the level of data that is permitted to be exported for this Web Part. Depending on your configuration, this setting may not be available.
Title URL Specifies the URL of a file containing additional information about the Web Part. The file is displayed in a separate browser window when you click the Web Part title.
Description Specifies the ScreenTip that appears when you rest the mouse pointer on the Web Part title or Web Part icon. The value of this property is used when you search for Web Parts by using the Search command on the Find Web Parts menu of the tool pane in the following Web Part galleries: Site, Virtual Server, and Web Part Page.
Help URL Specifies the location of a file containing Help information about the Web Part. The Help information is displayed in a separate browser window when you click the Help command on the Web Part menu.
Help Mode

Specifies how a browser will display Help content for a Web Part.

Select one of the following:

  • Modal Opens a separate browser window, if the browser has this capability. A user must close the window before returning to the Web page.
  • Modeless Opens a separate browser window, if the browser has this capability. A user does not have to close the window before returning to the Web page. This is the default value.
  • Navigate Opens the Web page in the current browser window.

 Note   Even though custom Microsoft ASP.NET Web Parts support this property, default Windows SharePoint Services 3.0 Help topics open only in a separate browser window.

Catalog Icon Image URL Specifies the location of a file containing an image to be used as the Web Part icon in the Web Part List. The image size must be 16 by 16 pixels.
Title Icon Image URL Specifies the location of a file containing an image to be used in the Web Part title bar. The image size must be 16 by 16 pixels.
Import Error Message Specifies a message that appears if there is a problem importing the Web Part.

SharePoint Designer


In SharePoint Designer 2010, you can create list views and data views as well as list forms and data forms. You create such views and forms to help site visitors interact with the data on the site and in the case of a custom solution, manage how data is presented and modified.

Every view and form you create in Microsoft SharePoint Designer 2010 is stored in a Web Part on an ASPX page. The Web Part contains the necessary code to render the view or form on the page as well as allow users to change the appearance of the data or submit data to the data source.

Depending on which view or form you choose and the type of data source you’re using, a different Web Part is added to the ASPX page. As you work with views and forms in SharePoint Designer 2010, you’ll want to be aware of which Web Part is added to the page because some of the Web Parts are editable in SharePoint Designer 2010, some in the browser, and some that require related SharePoint tools like InfoPath 2010.

List of Web Parts

The following table shows a quick comparison of the various Web Parts that are used for the views and forms you create in SharePoint Designer 2010.

Web Part Name Data sources When used Advantages, disadvantages
XSLT List View Web Part (XLV)

SharePoint lists

SharePoint libraries

External Lists

The standard and often default view associated with lists and libraries. The XLV is also used when you create a view on a page where the data source is a list or library. Full ribbon support in SharePoint, so the view can be customized in browser or SharePoint Designer. XLVs, however, can only be used for SharePoint lists and libraries, no other data sources.
XSLT List Form Web Part (XLF) External lists Serves as the default form for external lists in SharePoint. Can be used to write data to an external data source. Can only be customized using SharePoint Designer’s code view.
Data Form Web Part (DFWP)

SharePoint lists

SharePoint libraries

Databases

Web Services

XML files

Used by default when you create a data view to a data source other than a list and library. You can use a DFWP for lists and libraries when Data Source Details pane is used. Can be used as a view or a form to any data source- including lists, libraries, databases, and web services.
Data View Web Part (DVWP)

SharePoint lists

Share Point libraries

Database

Web Services

XML files

Was used in the previous releases of SharePoint Only used in certain upgrade scenarios in SharePoint 2010. Not used for new sites in SharePoint 2010, but available for backwards compatibility.
List Form Web Part (LFWP)

SharePoint lists

SharePoint libraries

The default list form used for SharePoint lists and libraries.

Well-formatted, easy to use form for users. To customize the form, however, you need to replace the form with a DFWP or upsize the forms to InfoPath.
List View Web Part (LVWP)

SharePoint lists

SharePoint libraries

Used for highly specialized view, like the Calendar view, Gantt view, and Datasheet view. Well-formatted and powerful view of the list or library. To customize the view, you must use SharePoint Designer’s code view.
InfoPath Form Web Part (IFWP) SharePoint lists Used to host InfoPath-based list forms. The IFWP is created when you customize list form in InfoPath 2010. Highly customizable and powerful forms generated by InfoPath 2010 form templates. Cannot be customized in SharePoint Designer.

XSLT List View Web Part

The XSLT List View Web Part, or XLV, provides a powerful, highly customizable view of a SharePoint list or library. The XLV is very unique among the Web Parts for views and forms because it can be customized using SharePoint Designer 2010 as well as in the browser using the SharePoint ribbon. As a result, both site designers and site users can customize the view and even take turns customizing it to meet their needs.

In SharePoint Designer, an XLV looks like this:

XSLT List View Web Part

When you work with an XLV, there are a few things to keep in mind. The Web Part is designed for SharePoint lists and libraries, which includes external lists. An XLV is not, however, compatible with other data sources, like database connections, Web service connections, or XML files. The view itself is not a form, in that it’s not intended to be used as a new item or edit item form, though you can enable inline editing so users can update individual fields in the view if they like.

Since the Web Part is written in XSLT, you can use all of SharePoint Designer’s view editing and WYSIWYG editing tools, and of course, code view.

XSLT List Form Web Part

The XSLT List Form Web Part, or XLF, holds the list form used for external lists in SharePoint. When you create an external content type for an existing business data source and then create an external list for this data source, an XLF is automatically created.

The XLF provides an important function for your site by allowing site visitors to use the form to write data to an external business data source. Unlike the previous XLV Web Part, however, you can only customize an XLF in the code view of SharePoint Designer. You can’t customize it using the list form or WYSIWYG editing tools.

Data Form Web Part

If you’ve worked in previous versions of SharePoint Designer, you will recognize the Data Form Web Part, or DFWP. This Web Part can be used to display read-only views of data and user-input forms for data.

The DFWP can be used for all of the available data sources in SharePoint Designer, including lists and libraries, database connections, Web Services, XML files, and more. This is one reason why you’ll see the DFWP used in various places in SharePoint Designer 2010. For example, when you create a new item, edit item, or display item form, the DFWP is added to the page. When you create a data view to a database connection, Web service, or XML file, the DFWP is added to the page.

The DFWP looks like this in SharePoint Designer 2010

Data Form Web Part

In SharePoint Designer, you can use the view and form editing tools as well as WYSIWYG editing tools to customize the DFWP. One thing to note about the DFWP, however, is that it cannot be customized in the browser as is the case with the XLV.

Data View Web Part

The Data View Web Part, or DVWP, was frequently used in previous releases of SharePoint as part of the DFWP. If you upgraded to SharePoint 2010, you may see this Web Part in use to support certain upgrade scenarios. The DVWP provides a degree of backwards compatibility for previously designed views and forms in earlier versions of SharePoint.

If you’re a new user to SharePoint 2010, however, you most likely won’t work with this Web Part as you create views and forms

List Form Web Part

The List Form Web Part, or LFWP, is used for the default list forms associated with SharePoint lists and libraries. These forms are highly formatted in a way that makes them easy to use by site visitors. If you don’t have a need to change them, you can simply use them as they are because they meet so many business purposes.

If you want to change their look and feel or form behavior, however, you can’t directly customize this Web Part directly in SharePoint Designer 2010. Instead, you have to create a new form, specifically a DFWP, and make it the default form for the list instead. Or, you can upsize the form to InfoPath 2010 and customize the forms in InfoPath Designer instead of SharePoint Designer.

In SharePoint Designer 2010, the LFWP might look something like this.

List Form Web Part

The preview of the form is a standard placeholder that doesn’t necessarily reflect the actual form you’re using. To see the real form, preview the page in a browser.

List View Web Part

The List View Web Part, or LVWP, is used for highly specialized, CAML-based views for SharePoint lists and libraries. These views include the Calendar view, the Gantt view, and the Datasheet View. These are views offer a powerful representation of data that in most cases don’t require a lot of customization.

In SharePoint Designer 2010, the LVWP might look something like this.

List View Web Part

Similar to the LFWP above, you see only a preview of the view in SharePoint Designer 2010 (in this case, a calendar view). The view itself is not directly customizable using the available view editing and WYSIWYG editing tools in SharePoint Designer 2010. To change the appearance of these views, you need to use code view or a developer application, like Visual Studio.

InfoPath Form Web Part

The InfoPath Form Web Part, or IPWP, is a kind of browser form Web Part that is updated by an associated InfoPath form template. Anytime, you upsize list forms to InfoPath 2010, you will see a new InfoPath form template file (.xsn) and new ASPX pages with this Web Part placed on them. The new ASPX pages replace the original form pages that you started with.

InfoPath 2010 is a powerful form design tool that you can use to create powerful, rules-based, and heavily branded forms for SharePoint lists, workflows, and form libraries.

In SharePoint Designer 2010, the IPWP might look something like this.

InfoPath Form Web Part

Again, you only see these if you choose to upsize your list forms to InfoPath 2010.