Creating Application Pages (_layouts) in MOSS 2007 - How to do rapid development using Form Field Controls

by Oscar 1/29/2008 4:22:00 PM

As you may or may not know, there are thousands of ways to accomplish development and customization tasks in MOSS 2007 and WSS 3.0.

At one point or another, as a MOSS Consultant, you will be faced with the task of creating custom application pages.  If you have an extensive web application development experience (much like I do), you will first think of using your web application techniques when faced with this task.  However, there are better and faster ways of accomplishing customization tasks around SharePoint. 

Today I will walk you through one of those scenarios where it would make sense to completely use your typical web application skills and techniques, then show you how to do it the MOSS way!


Scenario


You are creating a custom Site Provisioning Tool for MOSS 2007, and want to allow users to enter specific information so that the new site is created.  Once the site is created, you want to add an entry in a SharePoint List to track all the sites that have been created, and maybe if you are motivated create some custom views on the List to view by Region :) 

Solution


For example, I created some fields on my page that map to the fields on a SharePoint List to track newly created project sites on a List called Projects

This is what the page looks like when browsing to it.

clip_image001[4]

FIGURE 1 - Shows the custom site provisioning application page with all the form field controls rendered


The table below shows you the actual field type used for each field on the form.
SharePoint List Fields

Field Label Field Type
Project Title Text Field
IT Owner Person or Group
IT Group Choice Menu
Region Choice Menu


The table below shows you what out of the box SharePoint Form Controls you will use

Field Types and corresponding Field Controls used on ASPX page

Field Type Control Used
Project Title - Title FormField
IT Owner PeoplePicker
IT Group FormField
Region FormField

So here is the interesting part on this blog entry!

TIP: Throughout the various Application Pages on MOSS, there are samples of how the FormField is used.  Look around, you will be amazed what you can learn just by firing up VS 2005 and viewing the code for these pages! 

Rendering the Region Field (Choice) 

Our task here is to render the Region Field which is a Choice Menu on the SharePoint List. 

The Most Obvious Way of Populating the Choice Field
Now, typically, to render the drop down menu and populate it, you would probably do the following:

a) Drag a DropDownList Control on to the page
b) Wire an event handler on the page load event, and then query the SharePoint List using CAML
c) Iterate through the results and populate the DropDownList

The Rapid Method of populating the Choice Field

a) got to your page code and type code so that you can add a FormField Controls as such

clip_image001[4]

FIGURE 2 - Shows you how you can add an out of the box FormField, set its properties so it gets wired to the appropriate column on the SharePoint List 

NOTE: The FieldName should be the same as the one specified on the List
b) Wire the FormFields's OnInit event handler - this is where we are going to tell the FormField what List we are inserting data into.
c) Write code to get a handle on the List - I used a page global variable and set its value  on OnPreInit event
d) On the FormField's OnInit handler, specify the ListName property

And that's it!  Now if you browse to the aspx application page, you should see the DropDownList populated!


Rendering the IT Owner Field (PeoplePicker)


Have you ever wanted to use that nice User Picker Control that you see on various WSS/MOSS pages?  You can!

I dropped the People Picker onto my ASPX custom application page like so:

clip_image001

FIGURE 3 - How to specify a PeopleEditor Control in a declarative manner

To obtain the values the user has selected, you need to do something similar to my code-behid page below.  Here I am capturing the value (using PickerEntity Class), and inserting a new list item on my SharePoint List.

clip_image001[5]

FIGURE 4 - Shows you how to obtain or capture the values entered in the PeopleEditor Control.


TIP: One more thing I would like to point out in the code on Figure 4.  I am also inserting a value in a Hyperlink or Picture Field Type.  You will notice that after putting the url value, i have an additional piece of information, that is the link label! in this case, 'Go To Site'.  This is how it looks on the SharePoint List

clip_image001[7]

FIGURE 5 - Shows how the link label looks based on the code used on Figure 4 to programmatically populate the Hyperlink or Picture Field Type.


I hope this information is useful to you at some point!

Enjoy,
Oscar

Currently rated 1.9 by 8 people

  • Currently 1.875/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

WSS 3.0 | MOSS 2007 | CAML

Related posts

Comments

6/27/2008 1:19:59 AM

Thanks for this - no one else's site really takls about this subject! To make it easier are you able to supply some example source code with this so I can see how it all hangs together?

Jason gb

Add comment


 

  Country flag





Live preview

11/21/2008 3:38:08 PM

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About Me

Oscar Medina I am a SharePoint Solutions Architect based out of San Francisco, California.
You can read more about me here

E-mail me Send mail
View Oscar Medina's profile on LinkedIn

Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in