Saturday, September 26, 2015

Contact us page using and c# continued

Suggested Videos
Part 139 - How to upload and download files using and c#
Part 140 - Creating an image gallery using and c#
Part 141 - Contact us page using and c#

In Part 141, we discussed designing "contact us" page. In this video, we will implement the server side code. Once the form is submitted, an email should be sent to the support group. The email should contain all the details that are entered in the contact us form.
contact us page using and c#

Please make sure to include the following 2 namespaces.
using System;
using System.Net.Mail;

protected void Button1_Click(object sender, EventArgs e)
        if (Page.IsValid)
            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("");
            mailMessage.Subject = txtSubject.Text;

            mailMessage.Body = "<b>Sender Name : </b>" + txtName.Text + "<br/>"
                + "<b>Sender Email : </b>" + txtEmail.Text + "<br/>"
                + "<b>Comments : </b>" + txtComments.Text;
            mailMessage.IsBodyHtml = true;

            SmtpClient smtpClient = new SmtpClient("", 587);
            smtpClient.EnableSsl = true;
            smtpClient.Credentials = new 
                System.Net.NetworkCredential("", "YourGmailPassowrd");

            Label1.ForeColor = System.Drawing.Color.Blue;
            Label1.Text = "Thank you for contacting us";

            txtName.Enabled = false;
            txtEmail.Enabled = false;
            txtComments.Enabled = false;
            txtSubject.Enabled = false;
            Button1.Enabled = false;
    catch (Exception ex)
        // Log the exception information to 
        // database table or event viewer
        Label1.ForeColor = System.Drawing.Color.Red;
        Label1.Text = "There is an unkwon problem. Please try later";

If you are searching life partner. your searching end with now offer free matrimonial website which offer free message, free chat, free view contact information. so register here : Free matrimonial website