0

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?

4

2 回答 2

0

Are you sure it's here that the null reference is being thrown? Do you have a line number? Here the control is actually being checked for null.

My guess is that it's actually elsewhere in the code that it happens, because the .Text property is null. For example if you do something like:

txtPrimaryCompany.Text.Trim()

于 2014-08-13T13:18:07.700 回答
0

For some reason IEditableTextControl doesn't work on the field that I created. I used TextBox instead and it worked.

于 2014-08-16T04:15:00.013 回答