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 January 5th, 2012, 09:15 AM
Authorized User
 
Join Date: Dec 2011
Posts: 43
Thanks: 11
Thanked 0 Times in 0 Posts
Question Chapter 9/10 problem

Ever since the exercises on chapter 9 where you have to send emails my code has had a few problems. Now in my ContactForm when I try and submit it wont work, it used to give the error message "Could not find a part of the path 'C:\BegASPNET\Site\App_Data\ContactForm.txt" and said there was a problem in the line of code:
Code:
string mailBody = File.ReadAllText(fileName);
The line in my code
Code:
FormTable.Visible = false;
doesent compile, says that it doesent exist in current context so ive had to comment it out.

Ive tried to move on but all exercises go back to this contact form, so feel I need to fix these two problems before I deal with any others.

Any help would be apprieciated,

Nick
 
Old January 5th, 2012, 02:46 PM
Friend of Wrox
 
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
Arrow

Did you notice the line before you posted. it is something like this

Code:
string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
may be you have not created ContactForm.txt file in App_Data folder of your application or you must check for permissions to the App_Data folder (atleast read write)
__________________
Jack: Founder, Developer & Owner Of JackAndGenieForever.Com
The Following User Says Thank You to jack_hilary For This Useful Post:
Nick Makin (January 20th, 2012)
 
Old January 5th, 2012, 03:50 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

If this:
Code:
FormTable.Visible = false;
doesn't compile, check the markup of the page. Did you add Id and Runat attributes to the table?

You may want to look at the code for the book that you can download from this site, and see if you can spot the differences. Otherwise, please post the full code for the control.

Cheers,

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!
 
Old January 5th, 2012, 05:43 PM
Authorized User
 
Join Date: Dec 2011
Posts: 43
Thanks: 11
Thanked 0 Times in 0 Posts
Question

Thanks for the reply, no luck with the FormTable, still doesent compile for some reason.
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 Controls_ContactForm : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (!string.IsNullOrEmpty(PhoneHome.Text) ||
               !string.IsNullOrEmpty(PhoneBusiness.Text))
        {
            args.IsValid = true;
        }
        else
        {
            args.IsValid = false;
        }

    }
    protected void SendButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string fileName = Server.MapPath("~/App_Code/ContactForm.txt");
            string mailBody = File.ReadAllText(fileName);

            mailBody = mailBody.Replace("##Name##", Name.Text);
            mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
            mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text);
            mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text);
            mailBody = mailBody.Replace("##Comments##", Comments.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;
            FormTable.Visible = false;
        }
    }
}
And here is the markup for the table
Code:
<ContentTemplate>
<table id="ContactForm1" class="style1" runat="server">
    <tr>
        <td colspan="3" 
            style="font-weight: 700; text-decoration: underline; font-size: medium">
            <span class="style5">Get in touch with us!<br />
            </span>
            <br />
            Please complete this contact form in order for us to contact you.</td>
    </tr>
    <tr>
        <td class="style8">
            Name.</td>
        <td class="style3">
            <asp:TextBox ID="Name" runat="server"></asp:TextBox>
        </td>
        <td class="style7">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                ControlToValidate="Name" CssClass="ErrorMessage" ErrorMessage="Enter your name">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td class="style8">
            E-mail address</td>
        <td class="style3">
            <asp:TextBox ID="EmailAddress" runat="server"></asp:TextBox>
        </td>
        <td class="style7">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                ControlToValidate="EmailAddress" CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Enter an e-mail address">*</asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                ControlToValidate="EmailAddress" CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Enter a valid e-mail address" 
                ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
        </td>
    </tr>
    <tr>
        <td class="style8">
            E-mail address again</td>
        <td class="style3">
            <asp:TextBox ID="ConfirmEmailAddress" runat="server"></asp:TextBox>
        </td>
        <td class="style7">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                ControlToValidate="ConfirmEmailAddress" CssClass="ErrorMessage" 
                Display="Dynamic" ErrorMessage="Confirm e-mail address">*</asp:RequiredFieldValidator>
            <asp:CompareValidator ID="CompareValidator1" runat="server" 
                ControlToCompare="EmailAddress" ControlToValidate="ConfirmEmailAddress" 
                CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Re-type the e-mail address">*</asp:CompareValidator>
        </td>
    </tr>
    <tr>
        <td class="style8">
            Home phone number</td>
        <td class="style3">
            <asp:TextBox ID="PhoneHome" runat="server"></asp:TextBox>
        </td>
        <td class="style7">
            <asp:CustomValidator ID="CustomValidator1" runat="server" 
                ErrorMessage="*" 
                onservervalidate="CustomValidator1_ServerValidate" CssClass="ErrorMessage" 
                Display="Dynamic"></asp:CustomValidator>
        </td>
    </tr>
    <tr>
        <td class="style8">
            Business phone number</td>
        <td class="style3">
            <asp:TextBox ID="PhoneBusiness" runat="server"></asp:TextBox>
        </td>
        <td class="style7">
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style8">
            Comments</td>
        <td class="style3">
            <asp:TextBox ID="Comments" runat="server" Height="65px" TextMode="MultiLine" 
                Width="235px"></asp:TextBox>
        </td>
        <td class="style7">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                ControlToValidate="Comments" CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Enter a comment">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td class="style8">
            &nbsp;</td>
        <td class="style3">
            <asp:Button ID="SendButton" runat="server" Text="Send" 
                onclick="SendButton_Click" />
        </td>
        <td class="style7">
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style6" colspan="3">
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
                CssClass="ErrorMessage" 
                
                HeaderText="Please correct the following errors before you press the Send button" />
        </td>
    </tr>
</table>
<asp:Label ID="Message" runat="server" Text="Message Sent" Visible="False" />
 
Old January 5th, 2012, 05:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Your table has an ID of ContactForm1, not FormTable....

Hope this helps,

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:
Nick Makin (January 5th, 2012)
 
Old January 5th, 2012, 09:20 PM
Authorized User
 
Join Date: Dec 2011
Posts: 43
Thanks: 11
Thanked 0 Times in 0 Posts
Default

Thanks very much!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10, listing 10-10-app kiwibrit BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 2 August 18th, 2009 04:21 AM
chapter 10 problem nikItas BOOK: Beginning Access 2003 VBA 1 August 5th, 2008 08:54 AM
Chapter 10 problem rstoos Beginning PHP 1 September 16th, 2006 01:14 PM
Chapter 10 login problem Dennis Mollet BOOK: Beginning VB.NET Databases 1 August 18th, 2005 04:07 AM





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