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 June 22nd, 2011, 08:51 AM
Authorized User
 
Join Date: Jun 2011
Posts: 45
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chap 9 - E-Mail not working

Imar,

Here is a copy of my current code. I also had to change the name of sub from SendButton to just Send because your instructions said to name it Send.
Protected Sub Send_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Send.Click

As I mentioned, I also Dimensioned FormTable and initialiized it to True (Boolean)
Dim FormTable As Object
FormTable = True

At the bottom of the routine, I have commented out FormTable.Visible
' FormTable.Visible = False '


Imports System.IO ' Provides access to the File class for reading the file
Imports System.Net.Mail ' Provides access to the various mail related classes

Partial Class Controls_ContactForm
Inherits System.Web.UI.UserControl

Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
If Not String.IsNullOrEmpty(PhoneHome.Text) Or Not String.IsNullOrEmpty(PhoneBusiness.Text) Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub

Protected Sub Send_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Send.Click
If Page.IsValid Then
Dim fileName As String = Server.MapPath("~/App_Data/ContactForm.txt")
Dim mailBody As String = File.ReadAllText(fileName)
Dim FormTable As Object
FormTable = True

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)

Dim myMessage As MailMessage = New MailMessage()
myMessage.Subject = "Response from web site"
myMessage.Body = mailBody

myMessage.From = New MailAddress("[email protected]", "Jack Koyle")
myMessage.To.Add(New MailAddress("[email protected]", "Jack Koyle"))

Dim mySmtpClient As SmtpClient = New SmtpClient()
mySmtpClient.Send(myMessage)

Message.Visible = True
' FormTable.Visible = False '
End If
End Sub

End Class
Please advise me on what I've done wrong. I have tried to follow your book exactly.

Thank You,
jkoyle
Michigan, USA

Last edited by jkoyle; June 22nd, 2011 at 08:52 AM.. Reason: I forgot to include all the code
 
Old June 22nd, 2011, 09:16 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Code:
Dim FormTable As Object
FormTable = True
You need to remove this. FormTable is a control defined in the Markup. Can you post a copy of the markup of the control? Looks like you didn't assign this ID to the table. (see step 4 on page 324)

Quote:
I also had to change the name of sub from SendButton to just Send because your instructions said to name it Send.
Looks like you misunderstood the instructions. The text reads:

Quote:


Finally, into the second cell of the last row, drag a
Button. Rename the button to SendButton by setting its ID and set its Text property to Send.

So the control's ID (and thus the method) is called SendButton while the text that appears on the button is Send.


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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 16 pg 578. Hyperlink plus album not working tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 June 1st, 2016 04:56 PM
Chap 17: Email not working tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 August 17th, 2009 08:57 AM
Chap 17: Email not working tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 0 August 15th, 2009 09:09 AM
Chap 16 example not working John Cook BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 February 10th, 2006 05:40 PM





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