Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5.1 > BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : 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 9th, 2016, 02:00 PM
Registered User
 
Join Date: May 2016
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Default Chapter 9 - Error: 'System.Net.Mail.Message' is not accessible...

Hello,

I am getting an error in the final Email Try It Out. When loading the page I get the following error. The problem is in the "Message.Visible = True" line, but I can't figure out how to fix it.


"Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30389: 'System.Net.Mail.Message' is not accessible in this context because it is 'Friend'.

Source Error:

Line 35: mySmtpClient.Send(myMessage)
Line 36:
Line 37: Message.Visible = True
Line 38: FormTable.Visible = False
Line 39: End If


Source File: C:\BegASPNET\Site\Controls\ContactForm.ascx.vb Line: 37"

Below is all the code in the ContactForm.ascx.vb:

Code:
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(source As Object, args As ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
    If Not String.IsNullOrEmpty(PhoneHome.Text) OrElse Not String.IsNullOrEmpty(PhoneBusiness.Text) Then
      args.IsValid = True
    Else
      args.IsValid = False
    End If
  End Sub

  Protected Sub SendButton_Click(sender As Object, e As EventArgs) Handles SendButton.Click
    If Page.IsValid Then
      Dim fileName As String = Server.MapPath("~/App_Data/ContactForm.txt")
      Dim mailBody As String = 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)

      Dim myMessage As MailMessage = 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"))
      myMessage.ReplyToList.Add(New MailAddress(EmailAddress.Text))

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

      Message.Visible = True
      FormTable.Visible = False
    End If
  End Sub
End Class
 
Old June 9th, 2016, 03:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

What's the name of the Label control in the Markup? It looks like it's not Message but something else, causing Visual Studio to look for a Message class elsewhere (which it finds in System.IO.Mail).

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 June 9th, 2016, 03:28 PM
Registered User
 
Join Date: May 2016
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Default

There is no Label control. This is the ContctForm.ascx which only has a table, text boxes for user input, the validation controls and a "Send" button. When I comment out the line "Message.Visible = true", the code runs, and just displays a blank page (the Contact Form is not visible)
 
Old June 9th, 2016, 03:39 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 explains it then. There should be a label called Message. Maybe you missed a step?
__________________
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:
TI2016 (June 9th, 2016)
 
Old June 9th, 2016, 04:03 PM
Registered User
 
Join Date: May 2016
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Default

yes I did..Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
System.Net.Mail Problem With Time Out When Sending Adam Thompson Visual Basic 2005 Basics 5 November 10th, 2012 05:24 AM
need to add a reference to System.Net.Mail erik BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 January 9th, 2011 04:17 PM
System.Net.Mail Problems With Sending An Email Doom C# 3 May 25th, 2008 02:49 PM
Send calendar invite using System.Net.Mail bbeau .NET Framework 2.0 0 November 20th, 2007 09:28 PM
Mail Message in ASP.NET 2.0 sandeep patil ASP.NET 2.0 Basics 1 May 5th, 2005 12:45 AM





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