Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2012, 04:06 PM
Registered User
 
Join Date: May 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Sending Mail from a ContactUs page

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
 
Old May 30th, 2012, 04:32 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

That's strange. The code looks fine to me. Maybe there's something wrong with your Markup?

Also, maybe you have a second code behind file on disk? You can check with Windows Explorer in case VWD has hidden the file...

Otherwise, try restarting VWD or rebuild with the User Control files closed.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Chris73 (May 31st, 2012)
 
Old May 31st, 2012, 01:12 PM
Registered User
 
Join Date: May 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Sending Mail from ContactUs page

Hi Imar,

Thanks very much for your help. I have now solved the problem and the page build is now validating without any errors etc.

As you thought, I had another version of the site in my VWD folder which I deleted, then created a new web site in VWD and ensured that the folder location on my hard drive was correct.

Thanks again.





Similar Threads
Thread Thread Starter Forum Replies Last Post
ContactUs Khalil BOOK: Beginning ASP.NET 4 : in C# and VB 2 February 3rd, 2012 04:22 PM
problems sending mail with java mail gandacuboy J2EE 2 December 20th, 2006 03:05 PM
sending mail Sona1883 Classic ASP Components 1 January 3rd, 2005 07:25 AM
Sending e-mail to different mail box! Calibus Classic ASP Databases 4 September 3rd, 2004 05:48 PM
Sending both text mail and HTML mail - CDONTS madhukp Classic ASP Basics 1 October 8th, 2003 01:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.