Saturday , 28 May 2016
Home » .NET » Fancy Contact us Page Using ASP.NET

Fancy Contact us Page Using ASP.NET

Title : Contact us page using ASP.NET

Description :

I am going to design contact us page where you will fill up necessary fields and click button to submit it.

I will make use of few textboxes to enter some necessary fields and then at the end there will be a button called submit which will send data in form of an email notification.

Demo :

 Asp contact us form

 Email Notification : 

Email Notifiaction ASP.NET

.aspx Code :



 

Contact Us

   

   
 
 


Code Behind Button : 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AmazingThingsDemoOG
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

//This function will be called on button click to send email
protected void SendEMail()
{
try
{
//url of your website
String url = "YourURL";

//Email id and Password of that Email id which you will be using to send email
NetworkCredential loginInfo = new NetworkCredential("EmailId", "Password");

//Declare new MailMessage object and initialize with values such as from address, to address, bcc address, subject etc
MailMessage msg = new MailMessage();
msg.From = new MailAddress("FromAddress");
msg.To.Add(new MailAddress(emailTextBox.Text));
msg.Bcc.Add(new MailAddress("BccAddress"));
msg.Subject = "Notification from:Your Website Name";
msg.Body = "Hi," + nameTextBox.Text + "
Thanks for contacting us. We will contact you soon.
" + "Our System has recorded a message
" + messageTextBox.Text + "
Thanks and Regards
" + url;
msg.IsBodyHtml = true;

//Name the client which you will be using to send email.
SmtpClient client = new SmtpClient("smtp.gmail.com");

client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);
}
catch (Exception ex)
{
confirmationLabel.Text = ex.Message;
}

}

protected void submit_Click(object sender, EventArgs e)
{
try
{
//It Will call function SendEmail and confirms that message sent succesfully.
SendEMail();
confirmationLabel.Text = "Thanks for contacting us. We will get back to you in 24Hrs.";
confirmationLabel.Visible = true;
subjectTextBox.Text = "";
emailTextBox.Text = "";
nameTextBox.Text = "";
messageTextBox.Text = "";
}
catch (Exception) { }
}
}

}

 I have used CSS to make contact us page attractive.

CSS Code :

.TextBox
{
padding: 9px;
border: solid 1px #E5E5E5;
outline: 0;
font: normal 13px/100% Verdana, Tahoma, sans-serif;
width: 200px;
background: #FFFFFF url('bg_form.png') left top repeat-x;
background: -webkit-gradient(linear, left top, left 25, from(#FFFFFF), color-stop(4%, #EEEEEE), to(#FFFFFF));
background: -moz-linear-gradient(top, #FFFFFF, #EEEEEE 1px, #FFFFFF 25px);
box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px;
-moz-box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px;
-webkit-box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px;
}

.TextBox:hover, textarea:hover,
.TextBox:focus, textarea:focus
{
border-color: #C9C9C9;
-webkit-box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 8px;
}

.Button
{
width: auto;
padding: 9px 15px;
background: #617798;
border: 0;
font-size: 14px;
color: #FFFFFF;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
cursor: pointer;
}

This project was successfully compiled using  Microsoft Visual Studio 2012

About Vinayak Bamane

MCA from IMCOST College. Works as a Software Specialist with eClinicalWorks. Programming Worm, Trek lover, Rock Climber, Game Addict, Volleyball Player and happy to be with Amazing Things : )

Check Also

asp-net-ajax

Add AjaxControltoolkit to Visual Studio 2012

Ajax control toolkit contains rich set of controls which are used build highly responsive and …

3 comments

Leave a Reply

Your email address will not be published. Required fields are marked *