Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 30th, 2012, 04:06 PM
Registered User
Points: 36, Level: 1
Points: 36, Level: 1 Points: 36, Level: 1 Points: 36, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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("christian@christianrobson.orangehome.co.uk", "Sender Name");
            myMessage.To.Add(new MailAddress("christian@christianrobson.orangehome.co.uk", "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
Reply With Quote
  #2 (permalink)  
Old May 30th, 2012, 04:32 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
Chris73 (May 31st, 2012)
  #3 (permalink)  
Old May 31st, 2012, 01:12 PM
Registered User
Points: 36, Level: 1
Points: 36, Level: 1 Points: 36, Level: 1 Points: 36, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.