Hi Imar,
I have constructed a contact us page based on your example in Ch 9, p.323. When viewing in the browser on my local development server, the page works fine and drops the email into my temp folder.
However, when I have the page open in VWDExpress 2010 and click 'Build' the page produces the following build validation error:
------ Build started: Project: C:\WykehamGallery\Site\, Configuration: Debug Any CPU ------
Validating Web Site
Building directory '/Site/Account/'.
Building directory '/Site/Framing/'.
Building directory '/Site/Scripts/'.
Building directory '/Site/'.
C:\WykehamGallery\Site\ContactUs.aspx.cs(29,56): error CS0103: The name 'Subject' does not exist in the current context
C:\WykehamGallery\Site\ContactUs.aspx.cs(42,13): error CS0103: The name 'Message' does not exist in the current context
C:\WykehamGallery\Site\ContactUs.aspx.cs(43,13): error CS0103: The name 'ContactUsForm' does not exist in the current context
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
Here is my code behind page:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net.Mail;
public partial class ContactUs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SendButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", Name.Text);
mailBody = mailBody.Replace("##Telephone##", Telephone.Text);
mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
mailBody = mailBody.Replace("##Subject##", Subject.Text);
mailBody = mailBody.Replace("##Enquiry##", Enquiry.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("[email protected]", "Sender Name");
myMessage.To.Add(new MailAddress("[email protected]", "Receiver Name"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
Message.Visible = true;
ContactUsForm.Visible = false;
System.Threading.Thread.Sleep(5000);
}
}
}
Can you please tell me why this is happening?
Many Thanks