Wrox Programmer Forums
|
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 January 31st, 2016, 12:55 PM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 19: Configuring the Filesystem

Hi Imar,

At step 10 of the Try It Out, where I verify that everything is in order, I found that after I filled out the contact form and press the Send button, I get that error message "An error occurred..."

I believe the error occurs because my email address was not substituted in several locations in the web.config file from the Release folder. Please advise.

Here is the web.config code in my Release folder.
Code:
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
   <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
  </configSections>
  <connectionStrings>
    <add name="PlanetWroxConnectionString1" connectionString="Data 
         Source=.\SqlExpress;AttachDbFilename=|DataDirectory|\PlanetWrox.mdf;
         Integrated Security=True;User Instance=True" 
                    providerName="System.Data.SqlClient"/>
    <add name="PlanetWroxEntities" connectionString="metadata=
         res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl
         |res://*/App_Code.PlanetWrox.msl;provider=System.Data.SqlClient;
       provider connection string=&quot;data source=.\SqlExpress;  
         attachdbfilename=|DataDirectory|\PlanetWrox.mdf;
         integrated security=True;User Instance=True;
         MultipleActiveResultSets=True;App=EntityFramework&quot;"
         providerName="System.Data.EntityClient" />
  </connectionStrings>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms"/>
    <add key="FromAddress" value="[email protected]"/>
    <add key="FromName" value="Planet Wrox"/>
    <add key="ToAddress" value="[email protected]"/>
    <add key="ToName" value="Planet Wrox"/>
    <add key="SendMailOnError" value="true"/>
  </appSettings>
  <system.web>
    <trace mostRecent="true" enabled="false" requestLimit="100" pageOutput="false" localOnly="true"/>
    <customErrors mode="On" defaultRedirect="~/Errors/OtherErrors.aspx" redirectMode="ResponseRewrite">
      <error statusCode="404" redirect="~/Errors/Error404.aspx"/>
    </customErrors>
    <authentication mode="Forms">
      <forms loginUrl="~/Login"/>
    </authentication>
    <pages theme="Monochrome">
      <controls>
        <add tagPrefix="Wrox" tagName="Banner" src="~/Controls/Banner.ascx"/>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
      </controls>
    </pages>
    <compilation targetFramework="4.5.1" debug="true">
      <assemblies>
        <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
      <buildProviders>
        <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"/>
      </buildProviders>
    </compilation>
    <httpRuntime targetFramework="4.5.1"/>
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PlanetWroxConnectionString1" applicationName="/"/>
      </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PlanetWroxConnectionString1" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" applicationName="/"/>
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="DefaultRoleProvider">
      <providers>
        <add connectionStringName="PlanetWroxConnectionString1" applicationName="/" name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </providers>
    </roleManager>
    <!--
            If you are deploying to a cloud environment that has multiple web server instances,
            you should change session state mode from "InProc" to "Custom". In addition,
            change the connection string named "DefaultConnection" to connect to an instance
            of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
      -->
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PlanetWroxConnectionString1"/>
      </providers>
    </sessionState>
  </system.web>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="Planet Wrox &lt;[email protected]&gt;">
        <network host="your host"/>
      </smtp>
    </mailSettings>
  </system.net>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="NameServiceAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <services>
      <service name="NameService">
        <endpoint address="" behaviorConfiguration="NameServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="NameService"/>
      </service>
    </services>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
  <location path="Management">
    <system.web>
      <authorization>
        <allow roles="Managers"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.webServer>
    <defaultDocument>
      <files>
        <clear/>
        <add value="default.aspx"/>
        <add value="Default.htm"/>
        <add value="Default.asp"/>
        <add value="index.htm"/>
        <add value="index.html"/>
        <add value="iisstart.htm"/>
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>
 
Old January 31st, 2016, 03:42 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think the problem is this:

<network host="your host"/>

You need to enter a valid SMTP host.

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 February 1st, 2016, 02:07 AM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 19: Configuring the Filesystem

Hi Imar,

I added the network host. The first time I tried it after making the change, the Contact Us form scrolled upwards and then I received the error message "An error occurred while...". In subsequent tries, there is no scrolling of the Contact Us form upward, just the error message. No mail was sent at all.
 
Old February 1st, 2016, 09:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Does the test page you built earlier work?

Try temporarily removing the UpdatePanel and the try catch block so you can see the real error.

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 February 1st, 2016, 10:39 AM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 19: Configuring the Filesystem

]Hi Imar,

Everything worked before the Try It Out mentioned in the Title. I commented out the UpdatePanel and try/catch/finally block. I then ran the program and received the error message below.
Code:
Error occurred while restoring NuGet packages: Unable to locate the solution directory. Please ensure that the solution has been saved.
------ Build started: Project: Release, Configuration: Debug Any CPU ------
Validating Web Site
Building directory '/About/'.
Building directory '/MasterPages/'.
Building directory '/Controls/'.
(0): Build (web): c:\BegASPNET\Release\Controls\ContactForm.ascx.cs(18): error CS0103: The name 'PhoneHome' does not exist in the current context
(0): Build (web): c:\BegASPNET\Release\Controls\ContactForm.ascx.cs(18): error CS0103: The name 'PhoneHome' does not exist in the current context

C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(18,33): error CS0103: The name 'PhoneHome' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(18,74): error CS0103: The name 'PhoneBusiness' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(34,49): error CS0103: The name 'Name' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(35,50): error CS0103: The name 'EmailAddress' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(36,54): error CS0103: The name 'PhoneHome' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(37,58): error CS0103: The name 'PhoneBusiness' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(38,53): error CS0103: The name 'Comments' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(48,53): error CS0103: The name 'EmailAddress' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(53,11): error CS0103: The name 'MessageSentPara' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx.cs(54,11): error CS0103: The name 'FormTable' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx(32,50): error CS0103: The name 'PhoneHome' does not exist in the current context
C:\BegASPNET\Release\Controls\ContactForm.ascx(33,54): error CS0103: The name 'PhoneBusiness' does not exist in the current context
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
Here is the ContactUs.apcx.cs code.
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;              // Provides access to the File class for reading the file
using System.Net.Mail;     // Provides access to the various mail related classes

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_Data/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);

///        try
///        {
          MailMessage myMessage = new MailMessage();
          myMessage.Subject = "Response from web sites";
          myMessage.Body = mailBody;

          myMessage.From = new MailAddress(AppConfiguration.FromAddress, AppConfiguration.FromName);
          myMessage.To.Add(new MailAddress(AppConfiguration.ToAddress, AppConfiguration.ToName));
          myMessage.ReplyToList.Add(new MailAddress(EmailAddress.Text));

          SmtpClient mySmtpClient = new SmtpClient();
          mySmtpClient.Send(myMessage);

          MessageSentPara.Visible = true;
          FormTable.Visible = false;
 ///     }
        //catch (SmtpException)
        //{
        //  Message.Text = "An error occurred while sending your e-mail.  Please try again.";
        //}
        //finally
        //{
        //  Message.Visible = true;
        //}
      }
    }
}
There are a lot of red squiggly lines in the code.
 
Old February 1st, 2016, 11:40 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you also post the code for the ascx?

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 February 1st, 2016, 11:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Also, for this:

>> Error occurred while restoring NuGet packages: Unable to locate the solution directory. Please ensure that the solution has been saved.

try pressing Ctrl+Shift+S or click the Solution in the Solution Explorer and then choose File | Save As to save the solution.

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 February 1st, 2016, 10:38 PM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 19: Configuring the Filesystem

Hi Imar,

Here is the code for ContactForm.ascx.
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="Controls_ContactForm" %>
<style type="text/css">
  .auto-style1 {
    width: 100%;
  }
  .auto-style2 {
    height: 26px;
  }
  .auto-style3 {
  }
  .auto-style4 {
    width: 279px;
  }
  .auto-style7 {
    width: 279px;
    height: 26px;
  }
  .auto-style8 {
    width: 303px;
  }
  .auto-style9 {
    width: 406px;
    height: 26px;
  }
  .auto-style10 {
    width: 406px;
  }
  </style>
<script>
  function validatePhoneNumbers(source, args)
  {
    var phoneHome = document.getElementById('<%= PhoneHome.ClientID%>');
    var phoneBusiness = document.getElementById('<%= PhoneBusiness.ClientID %>');
    if (phoneHome.value != '' || phoneBusiness.value != '')
    {
      args.IsValid = true;
    }
    else
    {
      args.IsValid = false;
    }
  }
</script>
<%--<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
<div id="TableWrapper">
<table class="auto-style1" runat="server" id="FormTable" >
  <tr>
    <td class="auto-style2" colspan="3">Use the form below to get in touch with us.&nbsp; Enter your name, e-mail address, and your
      <br />
      home or business phone to get in touch with us.</td>
  </tr>
  <tr>
    <td class="auto-style10">Name</td>
    <td class="auto-style4">
      <asp:TextBox ID="Name" runat="server"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Name" CssClass="ErrorMessage" ErrorMessage="Enter you name">*</asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style10">E-mail address</td>
    <td class="auto-style4">
      <asp:TextBox ID="EmailAddress" runat="server" TextMode="Email"></asp:TextBox>
    </td>
    <td>
      <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="Emter a valid e-mail address" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style9">Repeat e-mail address</td>
    <td class="auto-style7">
      <asp:TextBox ID="ConfirmEmailAddress" runat="server" TextMode="Email"></asp:TextBox>
    </td>
    <td class="auto-style2">
      <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ConfirmEmailAddress" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Confirm the e-mail address">*</asp:RequiredFieldValidator>
      <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="EmailAddress" ControlToValidate="ConfirmEmailAddress" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="The e-mail adresses don't match">*</asp:CompareValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style10">Home phone number</td>
    <td class="auto-style4">
      <asp:TextBox ID="PhoneHome" runat="server"></asp:TextBox>
    </td>
    <td>
      <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validatePhoneNumbers" CssClass="ErrorMessage" Display="Dynamic" EnableTheming="True" ErrorMessage="Enter your home or business phone number" OnServerValidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style10">Business phone number</td>
    <td class="auto-style4">
      <asp:TextBox ID="PhoneBusiness" runat="server"></asp:TextBox>
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="auto-style10">Comments</td>
    <td class="auto-style4">
      <asp:TextBox ID="Comments" runat="server" Height="140px" TextMode="MultiLine" Width="398px"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="Comments" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Enter a comment">*</asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style10">&nbsp;</td>
    <td class="auto-style4">
      <asp:Button ID="SendButton" runat="server" Text="Send" OnClick="SendButton_Click" />
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="auto-style3" colspan="3">
      <asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="ErrorMessage" HeaderText="Please correct the following errors:" />
    </td>
  </tr>
</table>
</div>
<asp:Label ID="Message" runat="server" CssClass="Attention" Text="Message Sent" Visible="False" />
    <p runat="server" id="MessageSentPara" visible="false">Thank you for your message.  We'll get in touch with you if neccesay.</p>
    </ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" >
  <ProgressTemplate>
    <div class="PleaseWait">
      Please Wait...
    </div>
  </ProgressTemplate>
</asp:UpdateProgress>--%>
<script>
  $(function ()
  {
    $('form').bind('submit', function ()
    {
      if (Page_IsValid)
      {
        $('#TableWrapper').slideUp(3000);
      }
    });
  });
  function pageLoad()
  {
    $('.Attention').animate({width: '600px'}, 3000).animate({width: '100px'}, 3000).fadeOut('slow');
  }
</script>
As for saving the solution, Ctrl+Shift+S did not work and there is no File | Save As. Therefore, I rebuilt the solution, exited Microsoft Visual Studio 2013, and saved a *.sin file.
 
Old February 3rd, 2016, 12:14 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You have commented out the entire update panel including the form contents so the controls defined in that section no longer exist.

Just comment out / remove the opening and closing tags of the UpdatePanel and progress, leaving all inner controls active.

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!
 
Old February 3rd, 2016, 11:59 PM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 19: Configuring the Filesystem

Imar,

Here is my ContactForm.ascx form to check if I did the commenting out correctly.
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="Controls_ContactForm" %>
<style type="text/css">
  .auto-style1 {
    width: 100%;
  }
  .auto-style2 {
    height: 26px;
  }
  .auto-style3 {
  }
  .auto-style4 {
    width: 279px;
  }
  .auto-style7 {
    width: 279px;
    height: 26px;
  }
  .auto-style8 {
    width: 303px;
  }
  .auto-style9 {
    width: 406px;
    height: 26px;
  }
  .auto-style10 {
    width: 406px;
  }
  </style>
<script>
  function validatePhoneNumbers(source, args)
  {
    var phoneHome = document.getElementById('<%= PhoneHome.ClientID%>');
    var phoneBusiness = document.getElementById('<%= PhoneBusiness.ClientID %>');
    if (phoneHome.value != '' || phoneBusiness.value != '')
    {
      args.IsValid = true;
    }
    else
    {
      args.IsValid = false;
    }
  }
</script>
<%--<asp:UpdatePanel ID="UpdatePanel1" runat="server">--%>
  <ContentTemplate>
<div id="TableWrapper">
<table class="auto-style1" runat="server" id="FormTable" >
  <tr>
    <td class="auto-style2" colspan="3">Use the form below to get in touch with us.&nbsp; Enter your name, e-mail address, and your
      <br />
      home or business phone to get in touch with us.</td>
  </tr>
  <tr>
    <td class="auto-style10">Name</td>
    <td class="auto-style4">
      <asp:TextBox ID="Name" runat="server"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Name" CssClass="ErrorMessage" ErrorMessage="Enter you name">*</asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style10">E-mail address</td>
    <td class="auto-style4">
      <asp:TextBox ID="EmailAddress" runat="server" TextMode="Email"></asp:TextBox>
    </td>
    <td>
      <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="Emter a valid e-mail address" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style9">Repeat e-mail address</td>
    <td class="auto-style7">
      <asp:TextBox ID="ConfirmEmailAddress" runat="server" TextMode="Email"></asp:TextBox>
    </td>
    <td class="auto-style2">
      <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ConfirmEmailAddress" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Confirm the e-mail address">*</asp:RequiredFieldValidator>
      <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="EmailAddress" ControlToValidate="ConfirmEmailAddress" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="The e-mail adresses don't match">*</asp:CompareValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style10">Home phone number</td>
    <td class="auto-style4">
      <asp:TextBox ID="PhoneHome" runat="server"></asp:TextBox>
    </td>
    <td>
      <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validatePhoneNumbers" CssClass="ErrorMessage" Display="Dynamic" EnableTheming="True" ErrorMessage="Enter your home or business phone number" OnServerValidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style10">Business phone number</td>
    <td class="auto-style4">
      <asp:TextBox ID="PhoneBusiness" runat="server"></asp:TextBox>
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="auto-style10">Comments</td>
    <td class="auto-style4">
      <asp:TextBox ID="Comments" runat="server" Height="140px" TextMode="MultiLine" Width="398px"></asp:TextBox>
    </td>
    <td>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="Comments" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Enter a comment">*</asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td class="auto-style10">&nbsp;</td>
    <td class="auto-style4">
      <asp:Button ID="SendButton" runat="server" Text="Send" OnClick="SendButton_Click" />
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="auto-style3" colspan="3">
      <asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="ErrorMessage" HeaderText="Please correct the following errors:" />
    </td>
  </tr>
</table>
</div>
<asp:Label ID="Message" runat="server" CssClass="Attention" Text="Message Sent" Visible="False" />
    <p runat="server" id="MessageSentPara" visible="false">Thank you for your message.  We'll get in touch with you if neccesay.</p>
    </ContentTemplate>
<%--</asp:UpdatePanel>--%>
<%--<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" >--%>
  <ProgressTemplate>
    <div class="PleaseWait">
      Please Wait...
    </div>
  </ProgressTemplate>
<%--</asp:UpdateProgress>--%>
<script>
  $(function ()
  {
    $('form').bind('submit', function ()
    {
      if (Page_IsValid)
      {
        $('#TableWrapper').slideUp(3000);
      }
    });
  });
  function pageLoad()
  {
    $('.Attention').animate({width: '600px'}, 3000).animate({width: '100px'}, 3000).fadeOut('slow');
  }
</script>
I then ran the program and got the following error message:
"An exemption of type 'System.Net.Mail.SmtpException' occurred in System.dll but was not handled in user code

Additional information: The SMPT server requires a secure connection or the client was not authenticated. The server response was 5.7.0 Must issue a STARTTLS command first. 70sm12917041pfc69 - gsmtp

If there is a handler for this exception, the program may be safely continued."

The program stops at the line below in the ContactForm.ascx.cs file.
Code:
mySmtpClient.Send(myMessage);





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 19, Configuring the Filesystem tegandatagaard BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 2 November 4th, 2014 11:27 PM
Problem with using ASP.NET Configuration (Chapter 19 Configuring Security: Ex 13) TJinWI BOOK: Beginning Visual C# 2012 2 April 17th, 2014 11:48 AM
Chapter 19 page 574 Configuring Security: Ex 13 dsequoias BOOK: Beginning Visual C# 2012 0 April 16th, 2014 12:07 PM
Chapter 19: Configuring the File System (unable to open DB) Happs BOOK: Beginning ASP.NET 4.5 : in C# and VB 10 September 20th, 2013 04:07 AM
Chapter 2 Configuring Remote Debugging GarethHowell BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 1 July 8th, 2008 12:14 PM





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