I have two textboxes and I use FindControl()
to access them:
<tr>
<td align="right">
<asp:Label ID="LastNameLabel" AssociatedControlID="LastName" runat="server" /></td>
<td>
<asp:TextBox ID="LastName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="LastNameRequired" runat="server" ControlToValidate="LastName" Display="Dynamic"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PrimaryCompanyLabel" AssociatedControlID="PrimaryCompany" runat="server" /></td>
<td>
<asp:TextBox ID="PrimaryCompany" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="PrimaryCompanyRequired" runat="server" ControlToValidate="PrimaryCompany" Display="Dynamic"></asp:RequiredFieldValidator></td>
</tr>
The Textbox LastName
is being accessed fine but the second, PrimaryCompany
is returning a null reference
They are being access by:
private IEditableTextControl _txtLastName;
protected IEditableTextControl txtLastName
{
get
{
if (_txtLastName == null)
{
_txtLastName = (IEditableTextControl)this.CreateUserStep.ContentTemplateContainer.FindControl("LastName");
}
return _txtLastName;
}
}
private IEditableTextControl _txtPrimaryCompany;
protected IEditableTextControl txtPrimaryCompany
{
get
{
if (_txtPrimaryCompany == null)
{
_txtPrimaryCompany = (IEditableTextControl)this.CompleteStep.ContentTemplateContainer.FindControl("PrimaryCompany");
}
return _txtPrimaryCompany;
}
}
This code is from the SharePoint2013 FBAPack in CodePlex. The LastName
field is built-in while the PrimaryCompany
field is being added by me.
I'm only showing this part of the code as the null reference
is being thrown here. Am I missing something?