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)
            {
        ..
            }
        }

17.1.12

Writing to the SharePoint ULS Logs

try{
  ...
} catch (Exception ex) {
  SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("MSDN", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}

 

Product column is Unknown. This is the default behavior of the SPDiagnosticsService class

Unfortunately, interacting with a custom SPDiagnosticsService is available only in fully trusted farm solutions and not within sandboxed solutions.

To write to the ULS logs by using theSPDiagnosticsService class from the sandbox, developers can create a full trust proxy that the sandboxed solutions can call into