Click here to Skip to main content
11,709,844 members (73,880 online)
Click here to Skip to main content

Utilizing SharePoint Form Controls (like OWSDateField)

, 3 Jan 2006 56.6K 211 34
Rate this:
Please Sign up or sign in to vote.
This article discusses some ways to take advantage of the SharePoint client side controls (like the OWSDate Control) within the SharePoint web parts.

Introduction

If you have ever developed a WebPart for Windows SharePoint services, then you probably have tried to take advantage of some of the client-side controls, like the OWSDateField. If you have, then you know how much of a pain in the rear it is to use them.

The problem

There are several issues involved with using the OWS controls that come built-in with SharePoint services that are in the Microsoft.SharePoint.WebControls namespace:

  1. If you are going to use a control like the OWSDateField, then you must add an OWSForm control to the WebPart's child control collection. If you do not, then you will not be able to utilize the OWSField controls.
  2. If you wish to get the data from the control at the server (in other words, have the data posted back), you must create an OWSSubmitButton control and add it to the form. If you do not, any other posting mechanism will not post the user's input back to the server.

    This is the problem with OWSSubmitButton: there is no server side click event. Microsoft will tell you to check the "IsPostBack" property on the page, but that is not a viable option if you need more than one button that posts back the data, but does different tasks with it.

  3. None of the OWS form controls in the Microsoft.SharePoint.WebControls namespace have the data change events. Even if the data is not posted back, it will not fire an event.

To be blunt, the server-side functionality of the OWS control set is not very robust, yet the client side scripting works quite well.

The solution

For an application I developed in my current position, I needed the aforementioned functionality. However, I found nothing on the Internet that really helped me. Therefore, I dug deep into the server-side and client-side functionality of the OWS control set, and I found an elegant way of fixing the above limitations.

First, I created a base class called OWSBase that handled all of the data postback and value change event handling for all of the derived controls. Next, I created a set of controls (OWSTextField, OWSRichTextField, OWSDateField, OWSNumberField, etc.) derived from this base class, and each generated similar client-side JavaScripting that the SharePoint controls did. In the end, I created a submit button (a new OWSSubmitButton) that causes the form to postback the data and fire a server-side click event.

Here is the code for the OWSBase class:

public abstract class OWSBase : OWSControl, IPostBackDataHandler
{
    /// <span class="code-SummaryComment"><SUMMARY>
</span>

Here is the code for one of the derived controls, OWSDateField. (Note: This OWSDateField is not the same as the OWSDateField in the Microsoft.SharePoint.WebControls namespace):

public class OWSDateField : OWSBase
{
    #region construction

    /// <span class="code-SummaryComment"><SUMMARY>
</span>

Here is the code for the submit button:

/// <span class="code-SummaryComment"><SUMMARY>
</span>

Included in the download files are the following:

  • OWSChoiceField, which uses an Items property with the ListItem's objects to manage items in the choice, it can either be a dropdown list or a radio button choice field. Use the ChoiceFormat property to specify this.
  • OWSTextField, which can be a single or multi-line text field, use the NumLines property.
  • OWSRichTextField, which can get the HTML encoded text with a nice user interface (uses SharePoint client scripting). Use the NumLines property.
  • OWSNumberField

Assumptions

I assume you are familiar with developing WebParts for WSS or SPS. I will not give help with Manifext.xml or DWP files. These controls are meant to be used within the context of a SharePoint WebPart.

About the ZIP file

All that is included in the ZIP file are the source files. There is no project file. You may add these files to an existing project, or you may create a base assembly that you can reference in your WebPart projects.

TestWebPart.cs contains a small example of how to use the controls.

Special considerations

I have only tested these controls when they have been compiled into a class library that has been installed in the Global Assembly Cache, and thus fully trusted by SharePoint. You may need to make changes to the code or .config files if you do not sign your assembly with a strong name and install it in the GAC (using the - globalinstall option with stsadm.exe).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

railerb
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralWSS v3 b2 - OWSControl, OWSForm deprecated Pin
bytetec23-Oct-06 20:46
memberbytetec23-Oct-06 20:46 
GeneralRe: WSS v3 b2 - OWSControl, OWSForm deprecated Pin
portucale6-Feb-07 4:21
memberportucale6-Feb-07 4:21 
GeneralUse in aspx Pin
bytetec23-Oct-06 20:33
memberbytetec23-Oct-06 20:33 
QuestionHow to use? Pin
ShubhraSaxena28-Jun-06 21:51
memberShubhraSaxena28-Jun-06 21:51 
GeneralJS Error Pin
Carsten Isak Nielsen26-Jun-06 23:47
memberCarsten Isak Nielsen26-Jun-06 23:47 
AnswerRe: JS Error Pin
roxvogn7-Dec-06 10:38
memberroxvogn7-Dec-06 10:38 
QuestionProblem with the Submit Button styles Pin
briansgonefishing1-May-06 16:11
memberbriansgonefishing1-May-06 16:11 
GeneralQuestion About OWSTextField Pin
Daphoenix20-Mar-06 23:06
memberDaphoenix20-Mar-06 23:06 
GeneralRe: Question About OWSTextField Pin
railerb21-Mar-06 5:26
memberrailerb21-Mar-06 5:26 
I created the OWSLabel for read-only fields.
GeneralRe: Question About OWSTextField Pin
Daphoenix22-Mar-06 2:25
memberDaphoenix22-Mar-06 2:25 
GeneralRe: Question About OWSTextField Pin
railerb22-Mar-06 2:58
memberrailerb22-Mar-06 2:58 
GeneralGreat idea! Pin
KLehel17-Mar-06 9:29
memberKLehel17-Mar-06 9:29 
GeneralNice, But problem Pin
Daphoenix16-Mar-06 21:25
memberDaphoenix16-Mar-06 21:25 
GeneralRe: Nice, But problem Pin
railerb17-Mar-06 9:30
memberrailerb17-Mar-06 9:30 
GeneralRe: Nice, But problem Pin
Daphoenix19-Mar-06 21:20
memberDaphoenix19-Mar-06 21:20 
GeneralNicely Done! Pin
newkie13-Jan-06 0:56
membernewkie13-Jan-06 0:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150819.1 | Last Updated 3 Jan 2006
Article Copyright 2006 by railerb
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid