How to add a Comment field to the User page

From AbleCommerce Wiki
Revision as of 08:39, 19 August 2008 by Sohaib (Talk | contribs)

Jump to: navigation, search

Introduction

Sometimes there may be need to store comments for a particular user. It may be something like "What a swell guy" or it could even be "Problem customer: high RMA rate". Regardless of your reasons, it would be nice to have such a feature. Fortunately, the field exists in the database. It's just been left off the Edit User page for some reason. This modification describes how to easily add the field to the screen.

HTML Changes

The file we're going to change is ~/Admin/People/Users/EditUser.aspx. There is no code-behind file, so all the changes will occur in the same file.

Edit the file and find this section of code in the HTML section towards the end of the file:

                    <asp:DropDownList ID="Residence" runat="server">
                    <asp:ListItem Text="This is a residence" Value="1"></asp:ListItem>
                    <asp:ListItem Text="This is a business" Value="0"></asp:ListItem>
                    </asp:DropDownList>
                    </td>
                    </tr>

and replace all of it with this code:

                    <asp:DropDownList ID="Residence" runat="server">
                                <asp:ListItem Text="This is a residence" Value="1"></asp:ListItem>
                                <asp:ListItem Text="This is a business" Value="0"></asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <th class="rowHeader">
                            Comment:</th>
                        <td colspan="3">
                            <asp:TextBox ID="Comment" runat="server" Height="95px" 
                     TextMode="MultiLine" Width="445px"></asp:TextBox></td>
                    </tr>

We've changed the screen display but the page doesn't know how to save or load the actual field contents. Let's do that next....

Code Changes

There are two changes to made in the code. One reads the existing Comment field value into the page. The other writes it back to the User record before the record is saved.

First, find this line of code in the InitializeForm function near the beginning:

   codeResidence.SelectedIndex = (address.Residence ? 0 : 1);

and add this line immediately below it:

   Comment.Text = _User.Comment;

Now, find this line of code further down in the SaveUser() function:

   address.Residence = (Residence.SelectedIndex == 0);

and add this line immediately below it:

   _User.Comment = Comment.Text;

Save the page.

Testing

Go ahead and pull up your User page and edit any user. You should now see a large, unlimited text box below the address area. Try it out and type something into it, then Save the user. Return to your Dashboard, then again to the User page. Pull up the User and see if your changes were saved.

Conclusion

Having the ability to store comments with a particular user account can give an admin useful insight into the customer. Any opportunity to know more about who you are dealing with is an opportunity to succeed. Knowledge truly is power.