2010-06-09 4 views
0

J'ai SharePoint 2007 sur Windows Server 2003 SP1 (dans VM). J'exécute l'application web ici: http://vspug.com/nicksevens/2007/08/31/create-custom-field-types-for-sharepoint/MS-Sharepoint 2007: contrôle de champ personnalisé, TemplateContainer.FindControl renvoie toujours NULL

partie est ci-dessous:

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 = ""; 
      } 
     } 
    } 
} 

Cette ligne:

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

retourne toujours null.

J'ai supprimé base.CreateChildControls() mais il renvoie toujours null.

Toute aide serait grandement appréciée.

Répondre

2

Placez le fichier .ascx de votre contrôle directement sous le dossier CONTROLTEMPLATES et essayez.

Questions connexes