18.1.12

Why it returns null (control)TemplateContainer.FindControl("controlId")?

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LookUpProtocolCodeFieldControl.ascx.cs"
    Inherits="LookUpProtocolCodeProject.CONTROLTEMPLATES.LookUpProtocolCodeFieldControl"
%>
<SharePoint:RenderingTemplate runat="server" ID="LookUpProtocolCodeFieldControlTemplate"  >
    <Template>
        <table>
            <tr>
                <td>
                    <asp:DropDownList runat="server" ID="DDLLookUpProtocolCodeId">
                    </asp:DropDownList>
                </td>
            </tr>
        </table>
    </Template>
</SharePoint:RenderingTemplate>


protected override void CreateChildControls()
        {
            try
            {
                if (Field == null && this.ControlMode == SPControlMode.Display)
                { return; }

                base.CreateChildControls();

                DDLLookUpProtocolCode = (DropDownList)TemplateContainer.FindControl("DDLLookUpProtocolCodeId");
                if (DDLLookUpProtocolCode == null)
                    throw new SPException("Error: Cannot load the controls!");

                this.DDLLookUpProtocolCode.SelectedIndexChanged += new EventHandler(DropDownList_SelectedIndexChanged);
          

                DDLLookUpProtocolCode.TabIndex = TabIndex;
                DDLLookUpProtocolCode.CssClass = CssClass;
                DDLLookUpProtocolCode.ToolTip = Field.Title;
                PopulateDropDown();
            }
            catch (Exception ex)
            {
        ..
            }
        }

No comments:

Post a Comment