Click here to Skip to main content
15,895,779 members
Articles / Web Development / ASP.NET

Utilizing SharePoint Form Controls (like OWSDateField)

Rate me:
Please Sign up or sign in to vote.
4.56/5 (6 votes)
3 Jan 20063 min read 66.6K   216   34  
This article discusses some ways to take advantage of the SharePoint client side controls (like the OWSDate Control) within the SharePoint web parts.
using System;
using System.Text;
using System.Web.UI;

using Microsoft.SharePoint.WebControls;

namespace OWSControls
{
    public class OWSTextField : OWSBase
    {
        #region construction

        /// <summary>
        /// Default constructor
        /// </summary>
        public OWSTextField() { }

        #endregion

        #region custom properties

        /// <summary>
        /// Gets or set the number of lines for the richtext control. 
        /// </summary>
        public int NumLines
        {
            get
            {
                if (ViewState["NumLines"] == null)
                    NumLines = 1;
                return (int)ViewState["NumLines"];
            }
            set { ViewState["NumLines"] = value; }
        }

        #endregion

        #region overridden methods

        /// <summary>
        /// Renders the OWS Control
        /// </summary>
        /// <param name="wtr">writes out the text control information</param>
        protected override void Render(HtmlTextWriter wtr)
        {
            wtr.Write(
                "<SCRIPT>" +
                "fld = new {4}(frm, \"{0}\", \"{1}\", \"{2}\"); " +
                "fld.fRequired = {3}; " +
                "{5}" +
                "fld.IMEMode=\"\"; " +
                "fld.BuildUI(); " +
                "</SCRIPT>",
                UniqueID,
                Display,
                JavaScriptValue,
                Required.ToString().ToLower(),
                (NumLines == 1) ? "TextField" : "NoteField",
                (NumLines == 1) ? 
                    "fld.cchMaxLength = \"\"; " +
                    "fld.cchDisplaySize = \"\"; " : 
                    string.Format("fld.stNumLines = \"{0}\"; ", NumLines)
            );
        }
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions