Revision as of 08:11, 15 September 2008

Problem

How to write a custom control that provides you the Email functionality for example a small contact us control using the CommerceBuilder classes.

Solution

This tutorial will guide you how to create a feedback or contact control for your AbleCommerce powered store. The main purpose is to utilize the AbleCommerce CommerceBuilder API for utilizing the AbleCommerce configured SMTP settings.

Let's start by first creating a ContactUs.ascx file in Website/ConLib/ folder. It would be better to construct this feedback form as a ConLib user control so that it can be used any where on the store side.

After creating the file now copy and paste the following code into the ContactUs.ascx file.

Now contact us control is available and you can use it just like any other conlib control across the store.

[[ConLib:ContactUs SendTo="info@yourstore.com"]]

SendTo Property

The control exposes a SendTo property. You can use this property to specify the address at which you want to receive the Email. For example you want to recieve the Email at your Email address dedicated for customer feedback then the use of control will be as bellow.

[[ConLib:ContactUs SendTo="feedback@yourdomain.com"]]

Also keep in mind that if you don't provide any SendTo Email address then the control will be used the default Email address defined in the SMTP settings for store.

How can i add more fields to the contorl?

Almost each and every merchant including you has its own requirements. So a basic questoin may be in your mind too that how can i add my custom information to the control. You can do this job easily.
For example if you want to add user's last name as well then you can do this job in two steps

Step1:-

Modify the HTML to include a new text filed for Last Name. For example if we modify that part of code and add a new row just bellow the row having the name field and provide suitable ids for controls it will be something like.

Now in this step you need to modify the C# code so that this information can be sent within the Email. For this you need to modify the SendButton_Click function. You just need to add this extra information to the body of the Email as bellow