views:

87

answers:

0

I have SharePoint 2007 on Windows Server 2003 SP1 (in VM). I am running the web application here: http://vspug.com/nicksevens/2007/08/31/create-custom-field-types-for-sharepoint/

Part of it is below:

using System;

using System.Collections.Generic;

using System.Text;

using System.Web.UI.WebControls;



using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;



namespace CustomControl

{

    public class customfieldcontrol : BaseFieldControl

    {

        protected TextBox txtFirstName;

        protected TextBox txtLastName;



        protected override string DefaultTemplateName

        {

            get { return "CustomFieldRendering"; }

        }

        public override object Value

        {

            get

            {

                EnsureChildControls();

                return txtFirstName.Text + "%" + txtLastName.Text;

            }

            set

            {

                try

                {

                    EnsureChildControls();

                    txtFirstName.Text = value.ToString().Split('%')[0];

                    txtLastName.Text = value.ToString().Split('%')[1];

                }

                catch { }

            }

        }

        public override void Focus()

        {

            EnsureChildControls();

            txtFirstName.Focus();

        }

        protected override void CreateChildControls()

        {

            if (Field == null) return;

            base.CreateChildControls();



            //Don't render the textbox if we are  just displaying the field

            if (ControlMode == Microsoft.SharePoint.WebControls.SPControlMode.Display) return;



            txtFirstName = (TextBox)TemplateContainer.FindControl("txtFirstName");

            txtLastName = (TextBox)TemplateContainer.FindControl("txtLastName");

            if (txtFirstName == null) throw new NullReferenceException("txtFirstName is null");

            if (txtLastName == null) throw new NullReferenceException("txtLastName is null");

            if (ControlMode == Microsoft.SharePoint.WebControls.SPControlMode.New)

            {

                txtFirstName.Text = "";

                txtLastName.Text = "";

            }

        }

    }

}

This line:

txtFirstName = (TextBox)TemplateContainer.FindControl("txtFirstName");

always returns null.

I removed base.CreateChildControls() but it still returns null.

Any assistance would be greatly appreciated.