Are you using a form from one page to send the information to another page to send out an email? If so then is that page a aspx page?
Or are you just using the code behind of the form page to send out the email? If so then you would not use (CheckBox)PreviousPage.FindControl("brochure"); because there is no previous page.
You may need to explain more or show more code.
Edit: wow I have been checking and you must be using an old ver of asp.net if so then why can't you just remove the (CheckBox)PreviousPage.FindControl("brochure"); since you don't need it and pick up the values of the checkboxies like you did in the rest of the code.
Code:
<input type="checkbox" id="brochure" runat="server" name="brochure" value="brochure" style="width:15px;height:15px;margin:0 10px 0 0 " />Please tick to request our brochure</p>
<input type="checkbox" id="furtherInfo" name="furtherInfo" runat="server" value="further information" style="width:15px;height:15px;margin:0 10px 0 0 " />Please tick if you do not wish to receive further information from us</p>
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Net.Mail;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Yucca.Pentire.Dal;
using Yucca.Pentire.Utils;
public partial class contact : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Master.UpdateBodyTag("contactus");
Master.UpdateMetaDetails("contact");
PhoneTracking.ImageSwap();
phonenumber.Text = PhoneTracking.HeaderPhone;
submitbutton.Click += new ImageClickEventHandler(submitbutton_Click);
}
void submitbutton_Click(object sender, ImageClickEventArgs e)
{
if (ValdiateAllFields())
{
MailMessage msg = new MailMessage();
SmtpClient smtp = Smtp.CreateSMTP(1);
*******************************************************
//CheckBox brochure = (CheckBox) PreviousPage.FindControl("brochure"); Remove this
*********************************************************
string strBody;
strBody = "<strong>Name: </strong>" + name.Value + "<br />";
strBody += "<strong>Email: </strong>" + email.Value + "<br />";
strBody += "<strong>Telephone: </strong>" + telephone.Value + "<br />";
strBody += "<strong>Address: </strong>" + address1.Value + "<br />";
strBody += "<strong>Address: </strong>" + address2.Value + "<br />";
strBody += "<strong>Address: </strong>" + address3.Value + "<br />";
strBody += "<strong>Address: </strong>" + towncity.Value + "<br />";
strBody += "<strong>Address: </strong>" + county.Value + "<br />";
strBody += "<strong>Address: </strong>" + postcode.Value + "<br /><br />";
strBody += "<strong>Comments: </strong>" + comments.Value + "<br /><br />";
****************************************************************************
strBody += "<strong>Brochure: </strong>" + brochure.Value + "<br /><br />"; uncomment these two
strBody += "<strong>Further Info: </strong>" + furtherInfo.Value + "<br /><br />";
******************************************************************************
msg.From = new MailAddress("bookings@pentirehaven.co.uk");
msg.To.Add(new MailAddress("bookings@pentirehaven.co.uk"));
msg.To.Add(new MailAddress("leannetempest@yahoo.co.uk"));
msg.Subject = "Enquiry";
msg.Body = strBody;
msg.IsBodyHtml = true;
smtp.Send(msg);
headersentmessage.Visible = true;
Response.Redirect("~/contact_amended.aspx");
}
}
The only problem I see with this is brochure.Value will always give the value brochure even if its not checked. So you may need to add something like this
Code:
string myBrochure = "";
if (brochure.Checked)
{
myBrochure = brochure.Value;
}
Now instead of using brochure.Value in our email script use myBrouchure, this way if its not checked it will be an empty string.