Adding Membership Request Field

Aug 12, 2014 at 3:00 PM
Edited Aug 12, 2014 at 3:11 PM
I added a field in the membership request webpart:
<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>
I then added code in the MembershipRequestControl.cs to access the value of the new textbox:
private IEditableTextControl _txtPrimaryCompany;
        protected IEditableTextControl txtPrimaryCompany
        {
            get
            {
                if (_txtPrimaryCompany == null)
                {
                    _txtPrimaryCompany = (IEditableTextControl)this.CompleteStep.ContentTemplateContainer.FindControl("PrimaryCompany");
                }

                return _txtPrimaryCompany;
            }
        }
Unfortunately, the code above is throwing a null reference exception. Am I missing something?

Other codes I have added were mirrored with the FirstName field.
Coordinator
Aug 13, 2014 at 1:21 PM
Are you sure it's here that the null reference is being thrown? Do you have a line number?

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()
Aug 13, 2014 at 1:58 PM
Edited Aug 13, 2014 at 2:59 PM
Yes, I'm pretty sure this is where the null reference is being thrown.

I tried using the following instead of a getter-setter and it worked:
TextBox _txtPrimaryCompany = (TextBox)this.CreateUserStep.ContentTemplateContainer.FindControl("PrimaryCompany");
request.PrimaryCompany = _txtPrimaryCompany.Text;
Now my next problem is that the request does not appear in the Membership Review List. I have already enabled Review Membership Requests in the Site Configuration with no luck.

Also, I have added this in the CopyToReviewList method:
reviewItem[MembershipReviewListFields.PRIMARYCOMPANY] = request.PrimaryCompany;
Still no luck.
Aug 13, 2014 at 3:11 PM
It's working now. It turns out the second issue is caused by my Azure smtp server that was turned off.

Thanks!