Sunday, December 5, 2010

3CMS - ContactUs page (.aspx and codebehind)

Front End contact From Panels
 
following is the contact us page code. you can also ajaxify by configuring the ajax manager.
 
Code :
 

<asp:Panel ID="pnlContactForm" runat="server">

<p>

<strong>Please fill in the following form to contact us</strong></p>

<ol>

<li>

<label for="name">

Your Name

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please Fill in Your Name!"

ControlToValidate="rtbName" ValidationGroup="EmailFormValidate" Style="color: #FF0000">*</asp:RequiredFieldValidator><br />

</label>

<telerik:RadTextBox ID="rtbName" runat="server" EmptyMessage="Please Enter Your Name . . ."

Width="200px">

</telerik:RadTextBox>

</li>

<li>

<label for="email">

Email

<asp:RegularExpressionValidator ID="RegularExpressionValidator1"

runat="server" ErrorMessage="Please Fill in a valid Email Address!"

ControlToValidate="rtbEmail" ValidationGroup="EmailFormValidate"

Style="color: #FF0000"

ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please Enter Your Email Address!"

ControlToValidate="rtbEmail" ValidationGroup="EmailFormValidate" Style="color: #FF0000">*</asp:RequiredFieldValidator>

<br />

</label>

<telerik:RadTextBox ID="rtbEmail" runat="server" EmptyMessage="Enter You Email Address . . ."

Width="200px">

</telerik:RadTextBox>&nbsp;</li>

<li>

<label for="subject">

Subject<br />

</label>

<telerik:RadTextBox ID="rtbSubject" runat="server" EmptyMessage="What Your Comments are About?"

Width="200px">

</telerik:RadTextBox>

</li>

<li>

<label for="message">

Your comments

<%--<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Please Enter Minimum of 5 and Maximum of 500 characters !"

MinimumValue="5" ControlToValidate="rtbComments" ValidationGroup="EmailFormValidate"

Style="color: #FF0000" MaximumValue="500">*</asp:RangeValidator>--%>

<label for="email">

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Please Enter Some Comments to Send."

ControlToValidate="rtbComments" ValidationGroup="EmailFormValidate"

Style="color: #FF0000" ForeColor="Red">*</asp:RequiredFieldValidator>

</label>

<br />

</label>

<telerik:RadTextBox ID="rtbComments" runat="server" TextMode="MultiLine" Rows="5"

Width="350" EmptyMessage="Please Enter you comments here . . .">

</telerik:RadTextBox>

</li>

<li>

<asp:CheckBox ID="CheckBox1" runat="server" Text="Send copy of this message to me"

Checked="True" />

</li>

<li>

<telerik:RadCaptcha ID="RadCaptcha1" runat="server" ValidationGroup="EmailFormValidate"

ErrorMessage="Code does not match the Image. Please try again."

EnableRefreshImage="True" ForeColor="Red"

CaptchaLinkButtonText="Cannot Read Code? Refresh !"

CaptchaTextBoxLabel="Please Enter the code from the image">

</telerik:RadCaptcha>

</li>

<li class="buttons">

<asp:Button ID="contact" runat="server" Text="Submit" OnClick="contact_Click" ValidationGroup="EmailFormValidate" /><br /><br />

<span style="color: #FF0000">

<asp:ValidationSummary ID="ContactValidationSummary" runat="server"

ValidationGroup="EmailFormValidate" CssClass="ValidationSummary" /></span>

</li>

</ol>

</asp:Panel>

<asp:Panel ID="pnlReply" runat="server" Visible="False">

<p>

<strong>Thank you for your intrest and time in our website. We have recieved your comments and have been forwarded to the concerned person. Should it require any further details, a member of our staff may contact you.<br /><br /> We yet again Thank You for your time.<br /><br />Management.</strong></p>

</asp:Panel>

 

 

CodeBehind :

 

protected void Page_Load(object sender, EventArgs e)

{

Page.DataBind();

Globals.CurrentPageId = 6;

}

protected void contact_Click(object sender, EventArgs e)

{

//Add Comment to Database

ClientEntities db = new ClientEntities();

Comment comment = new Comment();

CommentRep commentRep = new CommentRep();

comment.ClientId = AppSession.Configs.ClientId;

comment.Name = rtbName.Text;

comment.Email = rtbEmail.Text;

comment.Subject = rtbSubject.Text;

comment.IsCopyRequested = CheckBox1.Checked;

comment.ClientAdminEmail = AppSession.Configs.ClientAdminEmail;

comment.CreatedBy = User.Identity.Name;

comment.DateCreated = DateTime.Now;

commentRep.Add(comment);

commentRep.Save();

// send email to the recepient

if (this.CheckBox1.Checked == true)

{

sendRecepientEmail();

}

//send email to the Site Adminisrator

sendClientEmail();

this.pnlContactForm.Visible = false;

this.pnlReply.Visible = true;

}

private void sendClientEmail()

{

MailMessage mail = new MailMessage();

mail.From = new MailAddress(AppSession.Configs.ClientAdminEmail, rtbName.Text + "(" + rtbEmail.Text + ")");

mail.To.Add(AppSession.Configs.ClientAdminEmail);

mail.Subject = "You have got new comments at " + AppSession.Configs.SiteTitle;

mail.IsBodyHtml = true;

mail.Body = "Visitor's Email : " + rtbEmail.Text + "<br /><br />";

mail.Body += "Comments left by " + rtbName.Text + " are as below : <br /><br />";

mail.Body += "Comments: <br />" + rtbComments.Text + "<br />";

SmtpClient smtp = new SmtpClient();

smtp.Send(mail);

}

private void sendRecepientEmail()

{

MailMessage mail = new MailMessage();

mail.From = new MailAddress(AppSession.Configs.ClientAdminEmail, AppSession.Configs.ClientName);

mail.To.Add(rtbEmail.Text);

mail.Subject = "Thank you for your comments at " + AppSession.Configs.SiteTitle;

mail.IsBodyHtml = true;

mail.Body = "Dear " + rtbName.Text + "<br /><br />";

mail.Body += "Thank you for your comments as below : <br /><br />";

mail.Body += "Comments: <br />" + rtbComments.Text + "<br />";

SmtpClient smtp = new SmtpClient();

smtp.Send(mail);

}

No comments:

Post a Comment