Поделиться через


Address Book Web Part

The Address Book Web Part lets shoppers create new addresses (including multiple locations) and edit or delete existing addresses. Shoppers can designate addresses as shipping or billing addresses, as well as primary and secondary addresses.

By default, the Address Book Web Part has fields for two address lines, city, region (state or province), postal code or zip code, country, and telephone number. The first address line, country, and telephone number are required fields. If the selected country is the United States or Canada, then the postal code or zip code field also becomes a required field. These fields are validated on the client side as well as the server side.

The Address Book Web Part field labels are based on the locale and culture of the form.

Architecture

You can use the Address Book Web Part in two possible deployment environments: Windows SharePoint Services (WSS) or Microsoft Office SharePoint Server (MOSS).

The Address Book Web Part contains the following:

  • AddressDetailWebPart: Dynamically loads the AddressDetail user control.

  • AddressType.ascx: A Web user control that manages the address type through a collection of check boxes to represent the address type. This user control has a property named EnableAddressTypeUpdate that, when set to True, updates the address type in the back-end repository, and otherwise manages the check boxes' checked status. In the Address Book Web Part, this property is set to False.

  • AddressDetail.ascx: Displays the shopper's address by using text boxes for free text values and drop-down lists for selections, such as region or country. The shopper can designate the address as a shipping address and/or a billing address by using check boxes.

The following table lists the mapping of the properties for the Address Book Web Part.

Property

Maps to

"Action" URL parameter

ActionQueryParameter

"Address detail" section title text

AddressDetailHeaderText

"Address Id" URL parameter

AddressIdQueryParameter

"Is billing address" check box text

BillingAddressCheckBoxText

"Cancel" button text

ButtonCancelText

"Remove" button text

ButtonRemoveText

"Save" button text

ButtonSaveText

"City" label text

CityLabelText

"City is required" message

CityRequiredErrorMessage

Use "delete confirmation" pop-up

ConfirmDeletion

"Country" label text

CountryLabelText

"Country is required" message

CountryRequiredErrorMessage

CSS class

CssClass

"Default billing address" check box text

DefaultBillingAddressCheckBoxText

"Default shipping address" check box text

DefaultShippingAddressCheckBoxText

"Delete confirmation" pop-up text

DeleteConfirmationMessage

"First name" label text

FirstNameLabel

"First name is required" message

FirstNameRequiredErrorMessage

Instructional text

InstructionText

"Last name" label text

LastNameLabel

"Last name is required" message

LastNameRequiredErrorMessage

"Line 1" label text

Line1LabelText

"Line 1 is required" message

Line1RequiredErrorMessage

"Line 2" label text

Line2LabelText

"Phone number format is invalid" message

PhoneNumberFormatValidatorErrorMessage

"Phone number" label text

PhoneNumberLabelText

"Phone Number is required" message

PhoneNumberRequiredErrorMessage

On completion, go to URL

PostActionPageUrl

"Postal code" label text

PostalLabelText

"Postal code is required" message

PostalRequiredErrorMessage

"Province" label text

ProvinceLabelText

"Postal code is invalid" message

RegexPostalFormatErrorMessage

"Zip code is invalid" message

RegexZipFormatErrorMessage

"Is shipping address" check box text

ShippingAddressCheckBoxText

"State" label text

StateLabelText

"State is required" message

StateRequiredErrorMessage

Default Mode

WebPartDefaultMode

"Zip code" label text

ZipLabelText

"Zip code is required" message

ZipRequiredErrorMessage

The following table lists the field length limits of the Address Book Web Part.

Field

Maximum length

Line1

60

Line2

60

City

40

Postal/zip code

10

Telephone

20

The following table lists the field validation defaults of the Address Book Web Part.

Field

Regular expression

Validation message

Postal code

[A-Z]\d[A-Z]\s\d[A-Z]\d

Postal code wrong format

Zip code

\d{5}(-\d{4})?

Zip code wrong format

Customization

You can modify the Address Book Web Part by modifying the .ascx file.

Error Handling

There is no design-time error handing required for this Web Part.

API Dependencies

The Address Book Web Part is dependent on the UserProfile API. Addresses are related to a profile and, therefore, are retrieved by using QueryRelatedItem<Address>. You can use the strongly typed Address properties Line1, AddressName, City, CountryRegionCode, StateProviceCode, and ZipPostalCode. You can also use the weakly typed properties Telephone and Line2.

Remarks

Developers can easily modify the validation expression for a phone number format. In the following example from the user control Billing.ascx, it is set to "[-() 0123456789]{6,20}". When changed, you do not need to restart the Web application; the new validation expression will be active immediately after saving the user control.

.
.
.
<td>
      *&nbsp;<asp:Label ID="lblContactPhone"  Text="<%$ Resources:OrderResources, ContactPhone %>"></asp:Label>
</td>
<td>
      <asp:TextBox ID="txtContactPhone"  MaxLength="50" />
</td>
<td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1"  ControlToValidate="txtContactPhone"
      ErrorMessage="<%$ Resources:OrderResources, ContactPhone_Required %>" Display="Dynamic" Text="*" ValidationGroup="Billing" Enabled='<%# radioEnter.Checked %>'>
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="PhoneNumberFormatValidator"  ControlToValidate="txtContactPhone" ValidationExpression="[-() 0123456789]{6,20}"  
      ErrorMessage="<%$ Resources:OrderResources, ContactPhone_Invalid %>" Display="Dynamic" Text="*" ValidationGroup="Billing" Enabled='<%# radioEnter.Checked %>'/>
</td>
.
.
.

See Also

Other Resources

Developing with SharePoint Commerce Services

Working With the Address Detail Web Part

Profile Administration System Web Parts