Asp.net MS Sharepoint 2007:自定义字段控件TemplateContainer.FindControl始终返回NULL

Asp.net MS Sharepoint 2007:自定义字段控件TemplateContainer.FindControl始终返回NULL,asp.net,sharepoint-2007,Asp.net,Sharepoint 2007,我在WindowsServer2003SP1(虚拟机)上安装了SharePoint2007。 我正在这里运行web应用程序: 部分内容如下: using System; using System.Collections.Generic; using System.Text; using System.Web.UI.WebControls; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; namespace

我在WindowsServer2003SP1(虚拟机)上安装了SharePoint2007。 我正在这里运行web应用程序:

部分内容如下:

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 = "";
            }
        }
    }
}
这一行:

txtFirstName = (TextBox)TemplateContainer.FindControl("txtFirstName");
始终返回null

我删除了
base.CreateChildControls()
,但它仍然返回null


非常感谢您的帮助。

将控件的.ascx文件放在CONTROLTEMPLATES文件夹下,然后重试