
268
CHAPTER 9 Building a Site ProviSioning SyStem
Finally, if the page is not posted back (in other words, it is loaded for the rst time, not reloaded as a
result of a button press or other event), the code performs the following:
Loads the Site Type drop-down list with values by calling LoadSiteTypes().
If an item has been loaded, form elds are loaded with the appropriate data by calling
LoadFields(), defined in the following section.
Secures form elds by calling SecureForm(), defined later.
These tasks need only be performed on page load because they set various controls’ state. These con-
trols’ state will be serialized into the page ViewState on subsequent postbacks, eliminating the need
to set that state on every page request.
Loading Form Data
Next, implement LoadFields()by adding the following function to your form:
private void LoadFields()
{
txtTitle.Text = item.Title;
txtURL.Text = (item[“SiteURL”] ?? “”).ToString();
ddlSiteType.SelectedValue = (item[“SiteType”] ?? “0”).ToString();
txtDescription.Text = (item[“Description”] ?? “”).ToString();
litStatus.Text = (item[“Status”] ?? “”).ToString();
txtApproverComments.Text =
(item[“ApproverComments”] ?? “”).ToString();
litProvisioningStatus.Text =
(item[“ProvisioningStatus”] ?? “”).ToString();
if (item[“Approver”] != null)
{
string login = new SPFieldUserValue(item.ParentList.ParentWeb,
item[“Approver”].ToString()).User.LoginName; ...